Reactjs 反应弹簧单组件安装/卸载

Reactjs 反应弹簧单组件安装/卸载,reactjs,jsx,react-spring,Reactjs,Jsx,React Spring,我尝试在使用React spring装载/卸载组件时创建动画: import { Transition, animated } from 'react-spring' ... export class CompName extends PureComponent<CompNamePropsType> { static defaultProps = { isExpanded: false, } render

我尝试在使用React spring装载/卸载组件时创建动画:

    import { Transition, animated } from 'react-spring'
    ...

    export class CompName extends PureComponent<CompNamePropsType> {
      static defaultProps = {
        isExpanded: false,
      }

      render() {
        const {
          isExpanded,
          ...props
        } = this.props

    return (
      <section className={styles.block} {...props}>
        <Transition
          from={{ opacity: 0 }}
          enter={{ opacity: 1 }}
          leave={{ opacity: 0 }}>
        {isExpanded && (style => (
           <animated.div style={{ ...style, background: "orange" }}>
             <AnotherComp />
           </animated.div>
        ))}
       </Transition>
      </section>
    )
  }
}
从'react spring'导入{转换,动画}
...
导出类CompName扩展了PureComponent{
静态defaultProps={
isExpanded:错,
}
render(){
常数{
我扩展了,
…道具
}=这是道具
返回(
{isExpanded&&(style=>(
))}
)
}
}
但这只是不起作用,我得到了一个错误
children不是一个函数
。我做错了什么,以及如何使用react spring wrapper在组件装载/卸载上创建动画?

正确的方法是:

<Transition items={isExpanded} native from enter leave>
  {isExpanded => isExpanded && (props => <animated.div style={props} />)
</Transition>


{isExpanded=>isExpanded&&(props=>

如果
isExpanded
是falsy,它将作为
子对象返回
Transition
组件,该组件似乎需要渲染prop,在
isExpanded
是真实的情况下,您可以使用三元运算符进行重构,并在时返回某种noop函数de>isExpanded
为falsy。@当isExpanded为'true'时,adz5A的错误为'TypeError:child不是函数',如果其'false'-'TypeError:_children不是函数',这是因为代码段中的
children
的签名不正确。它是一个返回函数的函数:
item=>props=>reactElement
。请参见。您的示例缺少
道具和
子项
道具的正确签名。