All Projects → devrnt → React Use Wizard

devrnt / React Use Wizard

Licence: mit
🧙 A React wizard (stepper) builder without the hassle, powered by hooks.

Programming Languages

javascript
184084 projects - #8 most used programming language
typescript
32286 projects

Projects that are alternatives of or similar to React Use Wizard

Hooks
Async middleware for JavaScript and TypeScript
Stars: ✭ 117 (-27.78%)
Mutual labels:  async, hooks, hook
React Query
⚛️ Hooks for fetching, caching and updating asynchronous data in React
Stars: ✭ 24,427 (+14978.4%)
Mutual labels:  async, hooks
Use Onclickoutside
React hook for listening for clicks outside of an element.
Stars: ✭ 361 (+122.84%)
Mutual labels:  hooks, hook
Fontmod
Simple hook tool to change Win32 program font.
Stars: ✭ 1,064 (+556.79%)
Mutual labels:  hooks, hook
MouseInjectDetection
Simple method of checking whether or not mouse movement or buttons (<windows 10) are injected
Stars: ✭ 29 (-82.1%)
Mutual labels:  hooks, hook
Radioactive State
☢ Make Your React App Truly Reactive!
Stars: ✭ 273 (+68.52%)
Mutual labels:  hooks, hook
Before After Hook
wrap methods with before/after hooks
Stars: ✭ 49 (-69.75%)
Mutual labels:  async, hooks
ngx-copilot
🏆 The most expected has arrived, a package for Angular that facilitates us to improve the experience of our users when guiding them in our interface
Stars: ✭ 61 (-62.35%)
Mutual labels:  wizard, stepper
React Selector Hooks
Collection of hook-based memoized selector factories for declarations outside of render.
Stars: ✭ 84 (-48.15%)
Mutual labels:  hooks, hook
Swifthook
A library to hook methods in Swift and Objective-C.
Stars: ✭ 93 (-42.59%)
Mutual labels:  hooks, hook
hookr
PHP action and filter hook system
Stars: ✭ 39 (-75.93%)
Mutual labels:  hooks, hook
React Intersection Observer
React implementation of the Intersection Observer API to tell you when an element enters or leaves the viewport.
Stars: ✭ 2,689 (+1559.88%)
Mutual labels:  hooks, hook
use-bus
React hook to subscribe and dispatch events accros React components
Stars: ✭ 51 (-68.52%)
Mutual labels:  hooks, hook
Swr
React Hooks for data fetching
Stars: ✭ 20,348 (+12460.49%)
Mutual labels:  hook, hooks
rusty-hook
git hook manager, geared toward Rust projects
Stars: ✭ 93 (-42.59%)
Mutual labels:  hooks, hook
Webhook
webhook is a lightweight incoming webhook server to run shell commands
Stars: ✭ 7,201 (+4345.06%)
Mutual labels:  hooks, hook
entangle
Global state management tool for react hooks inspired by RecoilJS and Jotai using proxies.
Stars: ✭ 26 (-83.95%)
Mutual labels:  hooks, hook
useAudioPlayer
Custom React hook & context for controlling browser audio
Stars: ✭ 176 (+8.64%)
Mutual labels:  hooks, hook
Ysf
YSF Server Functions
Stars: ✭ 77 (-52.47%)
Mutual labels:  hooks, hook
React Universal Hooks
🎉 React Universal Hooks : just use****** everywhere (Functional or Class Component). Support React DevTools!
Stars: ✭ 148 (-8.64%)
Mutual labels:  hooks, hook

react-use-wizard logo

react-use-wizard

A React wizard (stepper) builder without the hassle, powered by hooks.

ci version downloads minzipped size known vulnerabilities

Features

  • Simplicity
  • Focused on logic
  • Zero dependencies
  • No UI restrictions
  • Tiny size
  • Written in TypeScript

Installation

yarn add react-use-wizard

Quickstart

import * as React from 'react';

import { Wizard } from 'react-use-wizard';

const App = () => (
  <Wizard>
    <Step1 />
    <Step2 />
    <Step3 />
  </Wizard>
);

const Step1 = () => {
  const { handleStep, previousStep, nextStep } = useWizard();

  // Attach an optional handler
  handleStep(() => {
    alert('Going to step 2');
  });

  return (
    <>
      <button onClick={() => previousStep()}>Previous ⏮️</button>
      <button onClick={() => nextStep()}>Next </button>
    </>
  );
};

Links

API

Wizard

Wizard is used to wrap your steps. Each child component will be treated as an individual step. You can pass a shared footer and header component that should always be in your steps.

Example: pass a footer component that contains a "previous" and "next" button to the wizard.

Props

name type description required default
startIndex number Indicate the wizard to start at the given step 0
header React.ReactNode Header that is shown above the active step
footer React.ReactNode Footer that is shown below the active stepstep
children React.ReactNode Each child component will be treated as an individual step ✔️

Example

// Example: show the active step in the header
const Header = () => <p>I am the header component</p>;

// Example: show the "previous" and "next" buttons in the footer
const Footer = () => <p>I am the footer component</p>;

const App = () => {
  return (
    <Wizard startIndex={0} header={<Header />} footer={<Footer />}>
      <Step1 />
      <Step2 />
      <Step3 />
    </Wizard>
  );
};

useWizard

Used to retrieve all methods and properties related to your wizard. Make sure Wizard is wrapped around your component when calling useWizard.

handleStep is used to attach a handler to the step, can either be async or a sync function. This function will be invoked when calling nextStep.

Provide an optional stepIndex to either nextStep or previousStep to overwrite the default "step-flow" behaviour.

Remark - You can't use useWizard in the same component where Wizard is used.

Methods

name type description
nextStep (stepIndex?: number) => Promise Go to the next step. Overwrite the default behaviour by providing a step index
previousStep (stepIndex?: number) => void Go to the previous step. Overwrite the default behaviour by providing a step index
handleStep (handler: Handler) => void Attach a callback that will be called when calling nextStep. handler can be either sync or async
isLoading boolean * Will reflect the handler promise state: will be true if the handler promise is pending and false when the handler is either fulfilled or rejected
activeStep number The current active step of the wizard
isFirstStep boolean Indicate if the current step is the first step (aka no previous step)
isLastStep boolean Indicate if the current step is the last step (aka no next step)

Example

import * as React from 'react';

import { Wizard, useWiard } from 'react-use-wizard';

const App = () => (
  <Wizard>
    <Step1 />
    <Step2 />
    <Step3 />
  </Wizard>
);

const Step1 = () => {
  const {
    isLoading,
    isLastStep,
    isFirstStep,
    activeStep,
    previousStep,
    nextStep,
    handleStep,
  } = useWizard();

  // This handler is optional
  handleStep(() => {
    alert('Going to step 2');
  });

  return (
    <>
      <p>Step 1</p>
      {isLoading && <p>loading...</p>}
      <button onClick={() => previousStep()}>Previous</button>
      <button onClick={() => nextStep()}>Next</button>
      <div>
        Has next step: {!isLastStep ? '✅' : '⛔'}
        <br />
        Has previous step : {!isFirstStep ? '✅' : '⛔'}
      </div>
      Active step: {activeStep + 1} <br />
    </>
  );
};

It's recommended to pass the shared components to the header or footer in the Wizard to avoid duplication.

Playground

Small playground to showcase the functionalities of react-use-wizard: https://devrnt.github.io/react-use-wizard/

Following use cases are available in the playground

  • Simple wizard with async and sync steps
  • Animated wizard with sync steps
  • Integration with react-query (mutation on next step)

Source code can be found here.

Examples

Go to examples to check out some integrations (Gatsby, NextJS...).

Async

You can attach an async step handler to a step as well. Make sure to make to either pass an async function or return a promise (async) function:

const Step1 = () => {
  const { handleStep } = useWizard();

  // Async function
  handleStep(async () => {
    await fetch(...);
  });

  // OR

  // Return promise
  handleStep(() => {
    return fetch(...);
  });

  ...
}

Errors

If no errors are thrown then the wizard will go to the next step, so no need to call nextStep by yourself.

If an error is thrown in the attached function the wizard will just stay at the same step and will rethrow the error. (So you can try-catch in your attached function).

IsLoading

If an async function is attached to handleStep the isLoading property will indicate the loading state of the function. In general isLoading will reflect the handler promise state: will be true if the handler promise is pending and false when the handler is either fulfilled or rejected.

Animation

Since react-use-wizard is focused to manage the logic of a wizard it doesn't mean you can't add some animation by your own. Add any animation library that you like. I highly suggest framer-motion to add your animations.

Checkout this example to see how a step can be animated with framer motion.

IE11

Since Internet Explorer 11 doesn't support promises or async functions you'll need to install a polyfill for the regenerator-runtime.

In general using react-app-polyfill is recommended, it includes polyfills for various browsers.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].