Sca*_*Boy 4 javascript reactjs
当我运行 React.js 前端时,我收到此警告:
index.js:1446 Warning: Failed prop type: The prop `children` is marked as required in `InputAdornment`, but its value is `undefined`.
in InputAdornment (created by WithStyles(InputAdornment))
in WithStyles(InputAdornment) (at TopControls.js:101)
in div (created by InputBase)
in InputBase (created by Context.Consumer)
in WithFormControlContext(InputBase) (created by WithStyles(WithFormControlContext(InputBase)))
in WithStyles(WithFormControlContext(InputBase)) (created by Input)
in Input (created by WithStyles(Input))
in WithStyles(Input) (created by TextField)
in div (created by FormControl)
in FormControl (created by WithStyles(FormControl))
in WithStyles(FormControl) (created by TextField)
in TextField (at TopControls.js:91)
in div (created by Grid)
in Grid (created by WithStyles(Grid))
in WithStyles(Grid) (at TopControls.js:90)
in div (created by Grid)
in Grid (created by WithStyles(Grid))
in WithStyles(Grid) (at TopControls.js:89)
in div (at TopControls.js:22)
in TopControls (at BatchFlights.js:147)
in BatchFlights (created by WithStyles(BatchFlights))
in WithStyles(BatchFlights) (at App.js:23)
Run Code Online (Sandbox Code Playgroud)
第 10-102 行TopControls.js包含以下代码:
InputProps={{
startAdornment: <InputAdornment position="start"></InputAdornment>,
}}
Run Code Online (Sandbox Code Playgroud)
有人可以解释一下出了什么问题以及如何避免此警告吗?
小智 9
当您编写 时<InputAdornment position="start"></InputAdornment>,您不会将任何子级传递给 InputAdornment (例如,<InputAdornment position="start"><MyComponent /></InputAdornment>如果我想在 InputAdornment 中传递 MyComponent ,我可以编写children)。同时,propschildren被指定为requiredInputAdornment 的PropTypes. 有两种方法可以删除警告:
required从其 中删除说明符PropTypes。children像上面的示例一样传递给它。那么PropType's就满足要求了。| 归档时间: |
|
| 查看次数: |
16841 次 |
| 最近记录: |