How does this code work ? How can a function be called inside a component?
import React from 'react'
const ThemeContext = React.createContext('blue');
const App = () =>
<ThemeContext.Provider value={'green'}>
<ThemeContext.Consumer>
{(value) => <button style={{ background: value }}>Hello Context!</button>}
</ThemeContext.Consumer>
</ThemeContext.Provider>
export default App
I am trying to understand React Context internals , While it is clear how Context/Provider/Consumer can be used I just don't seem to understand how this line actually works calling a function inside of a component
<ThemeContext.Consumer>
{(value) => <button style={{ background: value }}>Hello Context!</button>}
</ThemeContext.Consumer>
Is it possible have the same pattern work inside of a custom component? This throws a warning 'Functions are not valid as a React child.
<div>
{(value)=><span>{value}</span>}
</div>