我很好奇知道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')不会)发生)。