Git Product home page Git Product logo

Comments (1)

drcmda avatar drcmda commented on May 3, 2024
const A = ({ opacity, ...allTheOtherProps }) => (
  <animated.div style={{ ...defaultStyles, opacity, backgroundColor: '#247BA0' }}>A</animated.div>
)
const B = ({ opacity }) => (
  <animated.div style={{ ...defaultStyles, opacity, backgroundColor: '#B2DBBF' }}>B</animated.div>
)

class App extends React.PureComponent {
  state = { toggled: true }
  toggle = () => this.setState(state => ({ toggled: !state.toggled }))
  render() {
    return (
      <div onClick={this.toggle}>
        <Transition
          native
          from={{ opacity: 0 }}
          enter={{ opacity: 1 }}
          leave={{ opacity: 0 }}>
          {this.state.toggled ? A : B}
        </Transition>
      </div>
    )
  }
}

Transition either accepts a list, in which case you give a list of functions that receive props:

{list.map(item => styles => <div style={styles} />} // styles contains the animated props

or a single item, so you give it a function that receives props:

{styles => <div style={styles} />}

You can pass on props to the receiving component by giving them to Transition directly:

        <Transition
          native
          ...
          transitionDoesntKnowMeButIWillBeForwardedAnyway={true}>

As for this part: ({ opacity, ...allTheOtherProps }), it's basic es6 destructuring, it helps sorting through the props you get. Here we extract opacity and collect everything else into allTheOtherProps, should you need them.

from react-spring.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.