React.createContext point of defaultValue?

前端 未结 2 1670
不知归路
不知归路 2021-02-11 13:10

On the React 16 Context doc page, they have examples that look similar to this:

const defaultValue = \'light\';
const SomeContext = React.createContext(defaultVa         


        
2条回答
  •  日久生厌
    2021-02-11 13:45

    When there's no Provider, the defaultValue argument is used for function createContext. This is helpful for testing components in isolation without wrapping them, or testing it with different values from Provider.

提交回复
热议问题