Skip to content

Commit

Permalink
fix comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Drew Atkinson committed Oct 6, 2023
1 parent d482dcb commit 9ef20c3
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion packages/nova-react/src/eventing/nova-eventing-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import type { NovaEvent, NovaEventing, EventWrapper } from "@nova/types";
import { InputType } from "@nova/types";
import invariant from "invariant";

// Initializing default with null to make sure providers are correctly placed in the tree
// Context is initialized with an empty object and this is null-checked within the hooks
const NovaEventingContext = React.createContext<INovaEventingContext>({});

// Both are optional in the context for initialization state only, but eventing must be supplied in the props
interface INovaEventingContext {
eventing?: NovaReactEventing;
unmountEventing?: NovaReactEventing;
Expand Down Expand Up @@ -104,6 +105,12 @@ export const useNovaEventing = (): NovaReactEventing => {
return eventing;
};

/**
* Used for eventing that should be triggered when the component is unmounted, such as within a useEffect cleanup function
* If unmountEventing has not been supplied to the NovaEventingProvider, this will fallback to use the defualt eventing instance
*
* @returns NovaReactEventing
*/
export const useNovaUnmountEventing = (): NovaReactEventing => {
const { unmountEventing } = React.useContext(NovaEventingContext);
invariant(
Expand Down

0 comments on commit 9ef20c3

Please sign in to comment.