Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation✏️: Show React hook integration example #8

Open
josias-r opened this issue Nov 7, 2022 · 4 comments
Open

Documentation✏️: Show React hook integration example #8

josias-r opened this issue Nov 7, 2022 · 4 comments
Labels
documentation Improvements or additions to documentation

Comments

@josias-r
Copy link
Owner

josias-r commented Nov 7, 2022

Show example how to integrate this library in a react application

@josias-r josias-r added the documentation Improvements or additions to documentation label Nov 29, 2022
@gupta82anish
Copy link

hey! Would really appreciate a tutorial for react integration :)
Great job with this library btw

@josias-r
Copy link
Owner Author

Hi and thank you!

I currently can't get around to describe an in depth example.

But the basic really just is as simple as creating a new Boarding class instance in a useEffect from a custom hook and returning it as a useState instance.

In that useEffect you can define the steps of the tour (I recommend working with custom data-* attributes to target elements) and them simply start the tour by calling boarding.start() on your custom hook returned object on any button press or user event.

Since BoardingJS evaluates elements live during the tour it should work great in React apps, as is, since elements only need to be available once they are being targeted.

Hope that helps!

@brandongs-MP
Copy link

brandongs-MP commented Oct 23, 2024

Hello @josias-r

I'm trying to implement in a nextjs/react application but when I change a step it doesn't re-render the component. And i want to show elements based on which step is the user. Can you help me to provide an example or how can I update a react state when boarding.js currentStep changes, please

Also another problem I have is that with Hot reload, a new instance of Boarding is created, is there a way to avoid that?

@josias-r
Copy link
Owner Author

Hi @brandongs-MP
If you want your react app to dynamically adjust while stepping trough the tour you can can call your react setState handlers on events like 'onHighlighted', does that solve your issue?

As for the HMR issue, it depends on how you are calling Boarding in your react app. Maybe with useEffect cleanups and a clean useEffect dependency management you can improve the behaviour. HMR has quite some react specific improvements, and with boarding.js being a vanilla library, it is limited in state persistance during HMR updates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

3 participants