因爲子組件有RouteComponentProps,所以在父組件中引用需要傳相應的屬性。但考慮到如果層級較深的話一層一層傳就很麻煩。而如果我們用route
組件引用的話就會很簡單,只需要在需要子組件的地方用route
的render
屬性就可以了:
<Route render={(props) =>
<InputItem
{...props}
onChange={(value) => this.handleInputChange(value)}
title={'手機號'}
/>