React.createContext point of defaultValue?

前端 未结 2 1418
走了就别回头了
走了就别回头了 2021-02-11 13:12

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:21

    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.

提交回复
热议问题