运行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)
TopControls.js
中的第10-102行包含以下代码:
InputProps={{
startAdornment: <InputAdornment position="start"></InputAdornment>,
}}
有人可以解释什么地方出了问题,我该如何避免此警告?
答案 0 :(得分:1)
在编写<InputAdornment position="start"></InputAdornment>
时,您不会将任何子代传递给InputAdornment(例如,如果我想在InputAdornment的<InputAdornment position="start"><MyComponent /></InputAdornment>
中传递MyComponent,则可以编写children
。
同时,道具children
在InputAdornment的required
中被指定为PropTypes
。
删除警告有两种方法:
required
中删除PropTypes
指定符。 children
传递给它。然后将满足PropType's
的要求。