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

Changing example to React functional components #110

Open
helios2003 opened this issue Feb 27, 2024 · 3 comments
Open

Changing example to React functional components #110

helios2003 opened this issue Feb 27, 2024 · 3 comments

Comments

@helios2003
Copy link

Is your feature request related to a problem?

As of 2024, most developers have been using React's functional components instead of Class-based components. Hence understanding the documentation of the library would be easy if components were written using functions. Look at the example here: https://codesandbox.io/embed/o2A4gwXE3

Describe the solution you'd like

Rewriting the examples to functional components.

Describe alternatives you've considered

No response

Additional Context

No response

@jcapogna
Copy link

jcapogna commented Jun 30, 2024

This is especially needed if you're using dynamic components as refs have changed.

An example of how to update dynamic components in a functional component:

const stepsRef = useRef<Steps>(null);

const onBeforeChange = async (nextStepIndex: number) => {
    if (nextStepIndex === 3) {
        await waitForElementToLoad()
        stepsRef.current?.updateStepElement(nextStepIndex)
    }
}

return (
    <Steps
        ...
        onBeforeChange={onBeforeChange}
        ref={stepsRef}
    />
)

@jaimefps
Copy link

jaimefps commented Aug 11, 2024

@jcapogna I've been fighting this for hours. Happy I found your comment. Note that I had to also account for a transition that moves the element across the screen, so I also have a delay in place to account for both te element mounting and the transition being done, pseudo code looks like:

const onBeforeChange = async (nextStepIndex: number) => {
  if (nextStepIndex === 3) {
    induceUiChange()
  
    await waitForElementToLoad()
  
    await delay(1000) // wait for transition to complete
  
    stepsRef.current?.updateStepElement(nextStepIndex)
  }
}

@jcapogna
Copy link

@jaimefps Glad it helped. I had to delay for a transition in my use case as well. I trigger an element to appear, which then results in an animation happening.

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

No branches or pull requests

3 participants