Skip to content

Commit

Permalink
refactor: refactored using the useUpdatableRef hook (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
woogie0303 authored Aug 27, 2024
1 parent 7f675f4 commit 71844eb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
7 changes: 4 additions & 3 deletions packages/core/src/FunnelRender.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Fragment, useMemo, useRef } from 'react';
import { Fragment, useMemo } from 'react';
import { AnyStepContextMap, FunnelHistory, FunnelStep, RouteOption } from './core.js';
import { FunnelRouterTransitionOption } from './router.js';
import { useUpdatableRef } from './utils.js';

export type FunnelStepByContextMap<TStepContextMap extends AnyStepContextMap, TRouteOption extends RouteOption> = {
[TStepKey in keyof TStepContextMap & string]: FunnelStep<TStepContextMap, TStepKey, TRouteOption>;
Expand Down Expand Up @@ -145,8 +146,8 @@ function useOverwriteFunnelHistoryTransitionArgument<
option?: FunnelRouterTransitionOption,
) => FunnelRouterTransitionOption,
): FunnelHistory<TStepContextMap, TStepKey, TRouteOption> {
const callbackRef = useRef(callback);
callbackRef.current = callback;
const callbackRef = useUpdatableRef(callback);

return useMemo(() => {
return {
...history,
Expand Down
3 changes: 1 addition & 2 deletions packages/core/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ interface Store<T> {
* A hook used to pass the state of the hook to a component when creating the component inside the hook.
*/
export function useStateSubscriberStore<T>(state: T) {
const stateRef = useRef(state);
stateRef.current = state;
const stateRef = useUpdatableRef(state);

const stateStoreRef = useRef<Store<T>>({
listeners: [],
Expand Down

0 comments on commit 71844eb

Please sign in to comment.