Global context introduced in #23324 #23367 help with resolving to one single context instance. However, this does not guarantee the forwards compatibility of default values in particular for nested objects and functions
// v1
React.createContext({
foo: 'string',
})
// v1.1
React.createContext({
// depends on usage but should be 'fine'
foo: 'string',
bar: 1,
// ⚠️ The below default properties will explode if they are used with v1 context
baz: () => null,
kevin: { current: null }
});
There is no guarantee that the the most recent version of the context is used. Therefore, default context values need to be forwards compatible. In particular this affects nested objects and default functions in context. These situations might not happen very often but will crash an app if they are used because of trying to access or call undefined.
This task includes two different sides
Global context introduced in #23324 #23367 help with resolving to one single context instance. However, this does not guarantee the forwards compatibility of default values in particular for nested objects and functions
There is no guarantee that the the most recent version of the context is used. Therefore, default context values need to be forwards compatible. In particular this affects nested objects and default functions in context. These situations might not happen very often but will crash an app if they are used because of trying to access or call
undefined.This task includes two different sides
useXXXContexthook instead of in theReact.createContextcallReact.createContextcall #23987