๐Ÿ› /Dev Tool

[ESLint] Prop spreading is forbiddeneslintreact/jsx-props-no-spreading

ํ•œ๋‚˜ 2022. 1. 31. 21:12

 

 

 

์•„๋ž˜์ฒ˜๋Ÿผ props๋ฅผ ํŽผ์นจ์—ฐ์‚ฐ์ž(spread operator)๋ฅผ ์“ฐ๋Š” ๊ฒƒ๋„ ESLint์—์„œ ๊ถŒ์žฅํ•˜๋Š” ํŒจํ„ด์€ ์•„๋‹ˆ๋‹ค. ์ฝ”๋“œ์˜ ๊ฐ€๋…์„ฑ๊ณผ ์œ ์ง€๋ณด์ˆ˜๋ฅผ ์œ„ํ•ด์„œ๋Š” ์–ด๋–ค prop์„ ๋‚ด๋ ค์ฃผ๊ณ  ์žˆ๋Š”์ง€ ์ผ์ผ์ด ๋ช…์‹œํ•˜๋Š” ๊ฒƒ์ด ์ข‹๋‹ค. 

Disallow JSX props spreading (react/jsx-props-no-spreading)
Enforces that there is no spreading props for any JSX attribute. This enhances readability of code by being more explicit about what props are received by the component. It is also good for maintainability by avoiding passing unintentional extra props and alllowing react to emit warnings when invalid HTML props are passed to HTML elemements.
<App {...props}>
  <MyCustomComponent {...props} some_other_prop={some_other_prop} />
  </App>

 

์•„๋ž˜์ฒ˜๋Ÿผ props๋ฅผ ๋ช…์‹œํ•ด์ฃผ์ž.

 

const { src, alt } = props;
const { one_prop, two_prop } = otherProps;

<MyCustomCOmponent one_prop={one_prop} two_prop={two_prop} />
<img src={src} alt={alt} />

Rule Options

"react/jsx-props-no-spreading": [<enabled>, {
    "html": "ignore" | "enforce",
    "custom": "ignore" | "enforce",
    "explicitSpread": "ignore" | "enforce",
    "exceptions": [<string>]     
}]
...

 

https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-props-no-spreading.md

 

GitHub - yannickcr/eslint-plugin-react: React specific linting rules for ESLint

React specific linting rules for ESLint. Contribute to yannickcr/eslint-plugin-react development by creating an account on GitHub.

github.com