-
Notifications
You must be signed in to change notification settings - Fork 7.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve contextType docs #1842
Comments
UPDATE: Turns out the problem I ran into has nothing to do with what was described below. The problem was the file extension. When I changed it to The remaining question then is, even though TypeScript no longer raises an error, can one still get into a circular dependency issue here? i.e., is it still best practice to have a import { createContext } from 'react';
export const SearchContext = createContext(null);
// ... other context object definitions RE:
React and ReactDOM: It seems like the above is the same cause for the following error from TypeScript. // SearchStore.ts
import { createContext } from 'react';
// I noticed in the docs that this can no longer be `createContext()`
// https://react.dev/reference/react/createContext#parameters
export const SearchContext = createContext(null);
export const SearchProvider = () => {
const store = useLocalObservable(() => ({
errorMessage: '',
page: PaginationConstants.DEFAULT_PAGE,
pageSize: PaginationConstants.DEFAULT_PAGE_SIZE,
results: [],
resultCount: 0,
}));
return <SearchContext.Provider /> // Cannot find namespace 'SearchContext'. ts(2503)
}; I first thought it might be related to the use of the arrow function, but I get the same with `export function SearchProvider() { ... }```. With all of that said 😃 the single file "component" here works with everything in the same file: Also, I am happy to help update the docs if this has not been addressed elsewhere, although I will need some guidance in doing so. |
See confusion in facebook/react#13969.
Specific action items:
.contextType
is available only since 16.6 (and corresponding RN/Expo release)createContext
value is the one you need to "update", we need to explain it's driven by stateThe text was updated successfully, but these errors were encountered: