<div align="center"> <a href="https://use-funnel.slash.page" title="@use-funnel - A powerful and safe step-by-step state management library"> <img src="../../docs/public/logo.png" width="200" /> <h2 align="center">@use-funnel</h2> </a> <p st
npm install @use-funnel/browser 
@use-funnel is a React Hook that helps you easily implement complex UI flows.
By comparing the type of the current step with the next, you can ensure that only the required states are managed safely.
Manage states based on history, making it easy to handle backward and forward navigation.
Supports browser history, react-router, next.js, @react-navigation/native, and more.
https://github.com/user-attachments/assets/8300d4ed-ab02-436e-a5a6-99c8d732e32f
``tsx
import { useFunnel } from '@use-funnel/browser';
export function App() {
const funnel = useFunnel<{
SelectJob: { jobType?: 'STUDENT' | 'EMPLOYEE' };
SelectSchool: { jobType: 'STUDENT'; school?: string };
SelectEmployee: { jobType: 'EMPLOYEE'; company?: string };
EnterJoinDate: { jobType: 'STUDENT'; school: string } | { jobType: 'EMPLOYEE'; company: string };
Confirm: ({ jobType: 'STUDENT'; school: string } | { jobType: 'EMPLOYEE'; company: string }) & { joinDate: string };
}>({
id: 'hello-world',
initial: {
step: 'SelectJob',
context: {},
},
});
return (
events: {
selectSchool: (_, { history }) => history.push('SelectSchool', { jobType: 'STUDENT' }),
selectEmployee: (_, { history }) => history.push('SelectEmployee', { jobType: 'EMPLOYEE' }),
},
render({ dispatch }) {
return (
onSelectEmployee={() => dispatch('selectEmployee')}
/>
);
},
})}
SelectSchool={({ history }) => (
history.push('EnterJoinDate', (prev) => ({
...prev,
school,
}))
}
/>
)}
SelectEmployee={({ history }) => (
history.push('EnterJoinDate', (prev) => ({
...prev,
company,
}))
}
/>
)}
EnterJoinDate={funnel.Render.overlay({
render({ history, close }) {
return (
onClose={() => close()}
/>
);
},
})}
Confirm={({ context }) =>
context.jobType === 'STUDENT' ? (
) : (
)
}
/>
);
}
declare function SelectJob(props: { onSelectSchool(): void; onSelectEmployee(): void }): JSX.Element;
declare function SelectSchool(props: { onNext(school: string): void }): JSX.Element;
declare function SelectEmployee(props: { onNext(company: string): void }): JSX.Element;
declare function EnterJoinDateBottomSheet(props: { onNext(joinDate: string): void; onClose(): void }): JSX.Element;
declare function ConfirmStudent(props: { school: string; joinDate: string }): JSX.Element;
declare function ConfirmEmployee(props: { company: string; joinDate: string }): JSX.Element;
`
Read our Contributing Guide to familiarize yourself with @use-funnel` development process, how to suggest bug fixes and improvements, and the steps for building and testing your changes.
MIT © Viva Republica, Inc. See LICENSE for details.