Changeset View
Changeset View
Standalone View
Standalone View
native/account/registration/registration-context-provider.react.js
// @flow | // @flow | ||||
import * as React from 'react'; | import * as React from 'react'; | ||||
import { RegistrationContext } from './registration-context.js'; | import { RegistrationContext } from './registration-context.js'; | ||||
import { useRegistrationServerCall } from './registration-server-call.js'; | import { useRegistrationServerCall } from './registration-server-call.js'; | ||||
import type { CachedUserSelections } from './registration-types.js'; | |||||
const emptyObj: CachedUserSelections = Object.freeze({}); | |||||
type Props = { | type Props = { | ||||
+children: React.Node, | +children: React.Node, | ||||
}; | }; | ||||
function RegistrationContextProvider(props: Props): React.Node { | function RegistrationContextProvider(props: Props): React.Node { | ||||
const [cachedSelections, setCachedSelections] = | |||||
React.useState<CachedUserSelections>(emptyObj); | |||||
const registrationServerCall = useRegistrationServerCall(); | const registrationServerCall = useRegistrationServerCall(); | ||||
const contextValue = React.useMemo( | const contextValue = React.useMemo( | ||||
() => ({ | () => ({ | ||||
register: registrationServerCall, | register: registrationServerCall, | ||||
cachedSelections, | |||||
setCachedSelections, | |||||
}), | }), | ||||
[registrationServerCall], | [registrationServerCall, cachedSelections], | ||||
); | ); | ||||
return ( | return ( | ||||
<RegistrationContext.Provider value={contextValue}> | <RegistrationContext.Provider value={contextValue}> | ||||
{props.children} | {props.children} | ||||
</RegistrationContext.Provider> | </RegistrationContext.Provider> | ||||
); | ); | ||||
} | } | ||||
export { RegistrationContextProvider }; | export { RegistrationContextProvider }; |