({ children, initialRelease })
| 31 | export const ReleaseProvider: FC< |
| 32 | PropsWithChildren<Types.ReleaseProviderProps> |
| 33 | > = ({ children, initialRelease }) => { |
| 34 | const { releases } = use(ReleasesContext); |
| 35 | const parentProvider = use(ReleaseContext); |
| 36 | |
| 37 | const [state, dispatch] = useReducer(reducer, { |
| 38 | ...releaseState, |
| 39 | // The initialRelease can only be `undefined` if a parent provider exists |
| 40 | // This is an intentional design flaw, forcing a context to exist. |
| 41 | // Note that if there is no parent provider the initial state for said provider will be used |
| 42 | version: initialRelease?.versionWithPrefix || parentProvider?.version, |
| 43 | }); |
| 44 | |
| 45 | const actions = useMemo(() => getActions(dispatch), [dispatch]); |
| 46 | |
| 47 | useEffect(() => { |
| 48 | // This allows us to nest one Release Provider unto another (whenever possible) |
| 49 | // and to actually set the version of a given provider based on a parent provider |
| 50 | // Which is super handy for the Download page to reuse other current Node.js states |
| 51 | if (parentProvider.version && parentProvider.version !== state.version) { |
| 52 | actions.setVersion(parentProvider.version); |
| 53 | } |
| 54 | // We should only react if the parentProvider changes |
| 55 | // eslint-disable-next-line @eslint-react/exhaustive-deps |
| 56 | }, [actions, parentProvider]); |
| 57 | |
| 58 | const release = useMemo( |
| 59 | () => releases.find(r => r.versionWithPrefix === state.version)!, |
| 60 | // Memoizes the release based on the version |
| 61 | // eslint-disable-next-line @eslint-react/exhaustive-deps |
| 62 | [state.version] |
| 63 | ); |
| 64 | |
| 65 | return ( |
| 66 | <ReleaseContext value={{ ...state, ...actions, release }}> |
| 67 | {children} |
| 68 | </ReleaseContext> |
| 69 | ); |
| 70 | }; |
nothing calls this directly
no test coverage detected