Skip to content

Commit

Permalink
fix(react-router-dom): remove the misplaced character } (#64)
Browse files Browse the repository at this point in the history
* fix: remove misspell

* refactor: define the name of searchParams  as a variable
  • Loading branch information
bigsaigon333 authored Sep 24, 2024
1 parent 4fb760d commit caa33a8
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions packages/react-router-dom/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@ export const useFunnel = createUseFunnel<ReactRouterDomRouteOption>(({ id, initi
const [searchParams, setSearchParams] = useSearchParams();
const navigate = useNavigate();

const currentStep = searchParams.get(`${id}.step`);
const currentContext = location.state?.[`${id}.context`];
const stepName = `${id}.step`;
const contextName = `${id}.context`;
const historiesName = `${id}.histories`;

const currentStep = searchParams.get(stepName);
const currentContext = location.state?.[contextName];
const currentState = useMemo(() => {
return currentStep != null && currentContext != null
? ({
Expand All @@ -27,7 +31,7 @@ export const useFunnel = createUseFunnel<ReactRouterDomRouteOption>(({ id, initi
}, [currentStep, currentContext, initialState]);

const history: (typeof initialState)[] = useMemo(() => {
const histories = location.state?.[`${id}.histories`];
const histories = location.state?.[historiesName];
if (Array.isArray(histories) && histories.length > 0) {
return histories;
} else {
Expand All @@ -44,15 +48,15 @@ export const useFunnel = createUseFunnel<ReactRouterDomRouteOption>(({ id, initi
push(state, { preventScrollReset, unstable_flushSync, unstable_viewTransition } = {}) {
setSearchParams(
(prev) => {
prev.set(`${id}.step`, state.step);
prev.set(stepName, state.step);
return prev;
},
{
replace: false,
state: {
...location.state,
[`${id}.context`]: state.context,
[`${id}.histories`]: [...(history ?? []), state],
[contextName]: state.context,
[historiesName]: [...(history ?? []), state],
},
preventScrollReset,
unstable_flushSync,
Expand All @@ -63,15 +67,15 @@ export const useFunnel = createUseFunnel<ReactRouterDomRouteOption>(({ id, initi
replace(state, { preventScrollReset, unstable_flushSync, unstable_viewTransition } = {}) {
setSearchParams(
(prev) => {
prev.set(`${id}.step`, state.step);
prev.set(stepName, state.step);
return prev;
},
{
replace: true,
state: {
...location.state,
[`${id}.context`]: state.context,
[`${id}.histories}`]: [...(history ?? []).slice(0, currentIndex), state],
[contextName]: state.context,
[historiesName]: [...(history ?? []).slice(0, currentIndex), state],
},
preventScrollReset,
unstable_flushSync,
Expand Down

0 comments on commit caa33a8

Please sign in to comment.