ESLint error: "Missing props in validation" in React ( Replacing it by PropTypes.checkPropTypes does not fix it )?
ESLint error: "Missing props in validation" in React ( Replacing it by PropTypes.checkPropTypes does not fix it )?
刚刚安装了 ESLint,它给了我一堆错误
例如我这里有这段代码。:
Ingredient.propTypes = {
ingredientsTouched: PropTypes.bool,
ingredientItem: PropTypes.string,
data: PropTypes.array(PropTypes.string),
text: PropTypes.string,
ingredientSetItem: PropTypes.bool,
ingredientIsInValid: PropTypes.arrayOf(
PropTypes.shape(PropTypes.bool, PropTypes.string)
)
}
这会给我另一个错误
Calling PropTypes validators directly is not supported by the `prop-types` package. Use `PropTypes.checkPropTypes()` to call them.
所以我将其转换为新格式
const myPropTypes = {
ingredientsTouched: PropTypes.bool,
ingredientItem: PropTypes.string,
data: PropTypes.array(PropTypes.string),
text: PropTypes.string,
ingredientSetItem: PropTypes.bool,
ingredientIsInValid: PropTypes.arrayOf(
PropTypes.shape(PropTypes.bool, PropTypes.string)
)
};
const props = {
ingredientsTouched: true,
ingredientItem: 'apple'
//etc...
}; //I guess this is just some test examples to demonstrate if our props are valid or not
but these are not the actual props of course
PropTypes.checkPropTypes(myPropTypes, props, 'prop', 'Ingredient');
但这会导致原来的错误:"Missing props in validation" as EsLint is not picking it
你打错了,用 arrayOf 代替 array
data: PropTypes.arrayOf(PropTypes.string),
刚刚安装了 ESLint,它给了我一堆错误
例如我这里有这段代码。:
Ingredient.propTypes = {
ingredientsTouched: PropTypes.bool,
ingredientItem: PropTypes.string,
data: PropTypes.array(PropTypes.string),
text: PropTypes.string,
ingredientSetItem: PropTypes.bool,
ingredientIsInValid: PropTypes.arrayOf(
PropTypes.shape(PropTypes.bool, PropTypes.string)
)
}
这会给我另一个错误
Calling PropTypes validators directly is not supported by the `prop-types` package. Use `PropTypes.checkPropTypes()` to call them.
所以我将其转换为新格式
const myPropTypes = {
ingredientsTouched: PropTypes.bool,
ingredientItem: PropTypes.string,
data: PropTypes.array(PropTypes.string),
text: PropTypes.string,
ingredientSetItem: PropTypes.bool,
ingredientIsInValid: PropTypes.arrayOf(
PropTypes.shape(PropTypes.bool, PropTypes.string)
)
};
const props = {
ingredientsTouched: true,
ingredientItem: 'apple'
//etc...
}; //I guess this is just some test examples to demonstrate if our props are valid or not
but these are not the actual props of course
PropTypes.checkPropTypes(myPropTypes, props, 'prop', 'Ingredient');
但这会导致原来的错误:"Missing props in validation" as EsLint is not picking it
你打错了,用 arrayOf 代替 array
data: PropTypes.arrayOf(PropTypes.string),