React何时解析其prop值

时间:2019-02-25 16:53:23

标签: reactjs

我很好奇知道React何时计算其prop值。例如,

const Button = styled.button``;

Button.defualtProps = {
    theme: () => {
        console.log('hello'); 
        return { myTheme: "light" }
    };
}

export default Button;

然后渲染该组件,并覆盖defaultProp theme

<Button theme={{myTheme: "dark"}} />

React是否先解析其defaultProp(将console.log('hello')发生),然后合并其传入的props还是将defaultProps与传入的props合并,然后解析其值(console.log('hello')不会)发生)。

0 个答案:

没有答案