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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example for how to go in function #4

Closed
hongbo-miao opened this issue Feb 26, 2018 · 8 comments
Closed

Example for how to go in function #4

hongbo-miao opened this issue Feb 26, 2018 · 8 comments

Comments

@hongbo-miao
Copy link

An example for how to go in function will be great. Thanks for the cool package!

handleGo = () => {
  // ...
}

<ReactMorph>
  {({ from, to, fadeIn, go }) => (
    <div>
      <a onClick={this.handleGo}>
        <strong {...from("title")}>ReactMorph 馃悰</strong>
        <br />
        <p {...from("description")}>Morphing transitions was never so easy!</p>
      </a>

      <div>
        <h1 {...to("title")}>ReactMorph 馃</h1>
        <br />
        <h2 {...to("description")}>Morphing transitions was never so easy!</h2>

        <a onClick={() => go(0)} {...fadeIn()}>
          Back
        </a>
      </div>
    </div>
  )}
</ReactMorph>
@beepcode
Copy link

beepcode commented Feb 28, 2018

Seems to have been added to the readme already:

<a onClick={() => go(1)}>

@hongbo-miao
Copy link
Author

Hi @beepcode, sorry for not clear. I mean using in user鈥檚 own function like the handleGo in the above code.

@beepcode
Copy link

Ok, the simplest solution would be to pass the go() function as a parameter. This would look like so:

handleGo = (go) => { go(); }

...

<a onClick={() => this.handleGo(go)}>

@hongbo-miao
Copy link
Author

hongbo-miao commented Feb 28, 2018

Thanks, @beepcode , that is what I thought.

But <a onClick={() => this.handleGo(go)}> will causing rerender, right?

If it is, maybe the author can export something like below to help avoid rerender?

import { morphGo } from "react-morph";

handleGo = () => {
  morphGo();
  // something else
}

@beepcode
Copy link

You could use the lifecycle method "shouldComponentUpdate()" to prevent rerender.

@hongbo-miao
Copy link
Author

Thanks, I get it.
Hope the package can handle those things. Better experience for the rest of people.

@beepcode
Copy link

What are you trying to achieve exactly? Which "business case" are you trying to find a solution to? From my perspective the sole purpose of "go()" is to start the morph, so rerender is expected. Or are you trying to trigger the morph from outside?

@hongbo-miao
Copy link
Author

Oh, you are right! I forget rerender is necessary in this case for the animation. My bad.

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

2 participants