136
rated 0 times
[
139]
[
3]
/ answers: 1 / hits: 71955
/ 6 Years ago, fri, april 20, 2018, 12:00:00
On the React 16 Context doc page, they have examples that look similar to this one:
const defaultValue = 'light'
const SomeContext = React.createContext(defaultValue)
const startingValue = 'light'
const App = () => (
<SomeContext.Provider theme={startingValue}>
Content
</SomeContext.Provider>
)
It seems that the defaultValue
is useless because if you instead set the startingValue
to anything else or don't set it (which is undefined
), it overrides it. That's fine, it should do that.
But then what's the point of the defaultValue
?
If I want to have a static context that doesn't change, it would be nice to be able to do something like below, and just have the Provider been passed through the defaultValue
const App = () => (
<SomeContext.Provider>
Content
</SomeContext.Provider>
)
More From » reactjs