How to set component default props on React component

后端 未结 9 893
孤街浪徒
孤街浪徒 2020-12-07 13:52

I use the code below to set default props on a React component but it doesn\'t work. In the render() method, I can see the output \"undefined props\" was printe

9条回答
  •  暖寄归人
    2020-12-07 14:28

    If you're using a functional component, you can define defaults in the destructuring assignment, like so:

    export default ({ children, id="menu", side="left", image={menu} }) => {
      ...
    };
    

提交回复
热议问题