我有一個非常簡單的應用程序做出反應,顯示總天數的多少,這些被漏診:如何將道具傳遞給React中的非呈現函數?
export const DayCount = (props) => (
<div>
<h4>Total days: { props.total }</h4>
<h4>Missed days: { props.missed } </h4>
</div>
);
export default class App extends React.Component {
render() {
return (
<DayCount total={10} missed={1} />
)
}
}
我想打一個計算器,顯示這是出席天%。然而,似乎道具不能以相同的方式傳遞給我的PercentageFunc函數?
export const PercentageFunc = (props) => {
return (props.total - props.missed)/props.total;
};
export const DayCount = (props) => (
<div>
<h4>Total days: { props.total }</h4>
<h4>Missed days: { props.missed } </h4>
<h1>% attended: { PercentageFunc() }</h1>
</div>
);
export default class App extends React.Component {
render() {
return (
<DayCount total={10} missed={1} />
)
}
}
好像你忘了將「道具」傳遞給* PercentageFunc()*? – QoP