Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs React-呈现库的父组件的PropType?_Reactjs_React Proptypes - Fatal编程技术网

Reactjs React-呈现库的父组件的PropType?

Reactjs React-呈现库的父组件的PropType?,reactjs,react-proptypes,Reactjs,React Proptypes,我有一个问题: 我使用的是react dates-picker库,我想知道:我不能定义proptype(比如我在哪里渲染datepicker我不使用任何props),但是在这种情况下,什么是好的react实践呢?当我不使用库,而是自己编写hild组件时,我会自己在子组件中定义proptype等。但是当我使用库时,如果“它们的代码”不那么容易查找,那会是什么呢?例如,我的案例(请参见下面的代码)强制要求属性“startDate”是一个对象。如果我以某种方式将其定义为我的组件,以便其他人可以轻松地看

我有一个问题: 我使用的是
react dates-picker
库,我想知道:我不能定义proptype(比如我在哪里渲染
datepicker
我不使用任何props),但是在这种情况下,什么是好的react实践呢?当我不使用库,而是自己编写hild组件时,我会自己在子组件中定义proptype等。但是当我使用库时,如果“它们的代码”不那么容易查找,那会是什么呢?例如,我的案例(请参见下面的代码)强制要求属性“startDate”是一个对象。如果我以某种方式将其定义为我的组件,以便其他人可以轻松地看到预期的内容,这会好吗? 我只是想写更好的代码,想知道在这种情况下什么是最好的。谢谢

export default class App extends React.Component {
   render(){
      return (
         <DayPickerRangeController
            startDate={this.state.startDate} // momentPropTypes.momentObj or null,
            endDate={this.state.endDate} // momentPropTypes.momentObj or null,
            onDatesChange={({ startDate, endDate }) => this.setState({ startDate, endDate })} // PropTypes.func.isRequired,
            focusedInput={this.state.focusedInput} // PropTypes.oneOf([START_DATE, END_DATE]) or null,
            onFocusChange={focusedInput => this.setState({ focusedInput })} // PropTypes.func.isRequired,
         />
      )
   }
}
导出默认类App扩展React.Component{
render(){
返回(
this.setState({startDate,endDate})//PropTypes.func.isRequired,
focusedInput={this.state.focusedInput}//PropTypes.oneOf([START_DATE,END_DATE])或null,
onFocusChange={focusedInput=>this.setState({focusedInput})}//PropTypes.func.isRequired,
/>
)
}
}

您可以定义一个包装器功能组件,将所有道具委托给子组件,并将道具类型与之关联

export const DayPickerWrapper = (props) => <DayPickerRangeController {...props}/>;

DayPickerWrapper.propTypes = { /* Add additional validations here */ }

在渲染中使用它之前导入它一次。

如果您将它写在组件
daypickeragecontroller
中,您定义irI我没有定义daypickeragecontroller,这就是我的问题的原因-如果我没有定义它,因为它是一个库,那么该怎么办
DayPickerRangeController.propTypes = {
  ...DayPickerRangeController.propTypes,
  // Add custom validations here
}