react/forbid-elements
eslint-plugin-react
No autofix
eslint.config.js
import react from "eslint-plugin-react";
export default [
{
plugins: { react },
rules: {
"react/forbid-elements": "error",
},
},
];// [1, { "forbid": ["button"] }]
<button />
React.createElement('button');
// [1, { "forbid": ["Modal"] }]
<Modal />
React.createElement(Modal);
// [1, { "forbid": ["Namespaced.Element"] }]
<Namespaced.Element />
React.createElement(Namespaced.Element);
// [1, { "forbid": [{ "element": "button", "message": "use <Button> instead" }, "input"] }]
<div><button /><input /></div>
React.createElement('div', {}, React.createElement('button', {}, React.createElement('input')));// [1, { "forbid": ["button"] }]
<Button />
// [1, { "forbid": [{ "element": "button" }] }]
<Button />Examples from the ESLint documentation.
react/forbid-elements
eslint-plugin-react
import react from "eslint-plugin-react";
export default [
{
plugins: { react },
rules: {
"react/forbid-elements": "error",
},
},
];react/forbid-elements
react plugin · restriction
{
"plugins": [
"react"
],
"rules": {
"react/forbid-elements": "error"
}
}correctness/noRestrictedElements
correctness · since 2.0.0
{
"linter": {
"rules": {
"correctness": {
"noRestrictedElements": "error"
}
}
}
}Disallow JSX prop spreading the same identifier multiple times
Enforce sandbox attribute on iframe elements
Enforce a defaultProps definition for every prop that is not a required prop
Enforce stateless components to be written as a pure function