1.0.2 • Published 6 years ago

@ewb/react-stepper v1.0.2

Weekly downloads
1
License
-
Repository
github
Last release
6 years ago

React stepper

Install

yarn add @ewb/react-stepper
npm install @ewb/react-stepper

playground

https://codesandbox.io/s/k28p9025or

How to use

Provider

import { StepperProvider } from '@ewb/react-stepper';

// props: "start" will automatically step into the first action component
function App() {
    return (
        <StepperProvider start>
            {...}
        </StepperProvider>
    );
}

Step

import { useStepper } from '@ewb/react-stepper';

function SomeStepComponent() {
  const [state, setState] = useState(false);
  const { nextStep } = useStepper(action, {
    state: [state, setState], // This is used for going prevState
    preNext
  });

  function action() {
    setState(true);
  }

  function preNext() {
    setState(false);
  }
  
  return (
    { active ? <>Active</> : <>Not active</> }
  )
}

Watcher

import { useStepWatcher } from '@ewb/react-stepper';

function SomeWatcherComponent() {
    const { reset } = useStepWatcher(state => {
        console.log('state change', state);
    });
    
    return (
    <div>
      ResetStepper
      <button onClick={reset}>Reset</button>
    </div>
    )
}
1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago