ReactJS: Warning: setState(…): Cannot update during an existing state transition

后端 未结 11 1112
一个人的身影
一个人的身影 2020-11-27 10:32

I am trying to refactor the following code from my render view:

11条回答
  •  渐次进展
    2020-11-27 10:43

    If you are trying to add arguments to a handler in recompose, make sure that you're defining your arguments correctly in the handler. It is essentially a curried function, so you want to be sure to require the correct number of arguments. This page has a good example of using arguments with handlers.

    Example (from the link):

    withHandlers({
      handleClick: props => (value1, value2) => event => {
        console.log(event)
        alert(value1 + ' was clicked!')
        props.doSomething(value2)
      },
    })
    

    for your child HOC and in the parent

    class MyComponent extends Component {
      static propTypes = {
        handleClick: PropTypes.func, 
      }
      render () {
        const {handleClick} = this.props
        return (
          
    ) } }

    this avoids writing an anonymous function out of your handler to patch fix the problem with not supplying enough parameter names on your handler.

提交回复
热议问题