简体   繁体   English

那个道具是什么意思?

[英]What does that props mean?

In this example:在这个例子中:

class TodoList extends Component {
  constructor(props) {
    super(props);
  }

  render() {
    return (
      <div>
        <Route
          path="/todos/new"
          component={props => <NewTodoForm {...props} />}
        />
      </div>
    );
  }
}

In the NewTodoForm component, it reaches the {...props} by using在 NewTodoForm 组件中,它通过使用到达{...props}

this.props.history.push("url")

I am confused that in {...props} , why does it use props rather than this.props ?我很困惑,在{...props} ,为什么它使用props而不是this.props I know that is a stateless function and props is a parameter.我知道这是一个无状态函数,props 是一个参数。 But where does that props come from?但是这些道具是从哪里来的呢?

Any help or comment will be appreciated, thanks.任何帮助或评论将不胜感激,谢谢。

component={props => <NewTodoForm {...props} />}

is using the render prop pattern, ie having a prop that is a function that returns something for the parent component to render.正在使用渲染道具模式,即有一个道具是一个函数,它返回一些东西供父组件渲染。

The parameters passed to a render prop function could be anything, but in react-router'scomponent prop's case , it'll be the route props object, ie {match, location, history} .传递给渲染道具函数的参数可以是任何东西,但在 react-router 的component道具的情况下,它将是路由道具对象,即{match, location, history}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM