americanexpress / react-albus

✨ React component library for building declarative multi-step flows.
Apache License 2.0
1.1k stars 89 forks source link

How to switch into specific step on click event from a button in another step #39

Closed rahulgit closed 4 years ago

rahulgit commented 5 years ago

Is there any option to Switch to a specific step from on click `

Gandalf

` here I need to Switch to `dumbledore` When clicking **Go to Dumbledore**
jdconner commented 5 years ago

@rahulgit when using Step's render prop, you have access to the router functions. From there, you can use push:

<Steps>
    <Step id="gandalf" render={({ push }) => (
        <>
            <h1 className="text-align-center">Gandalf</h1> 
            <button className="btn-fluid margin-1-b" onClick={() => push('dumbledore')} >Go to Dumbledore</button> 
        </>
    ) /> 
    //Other steps, including 'dumbledore'
</Steps>

You also have access to the push router function from the WithWizard component.

 <WithWizard
     render={({ push }) => ...

See https://github.com/americanexpress/react-albus#contextwizard for more info on what you can use from the wizard context.