English 中文(简体)
为什么反应使用 国家反应有参数 开始于“ 设置 ”?
原标题:why react s useState response has parameter starting with "set"?

在反应中,当我们使用状态时,我们写出以下代码:

const [abc, setAbc] = useState("")

在这种情况下, 为什么“ SetAbc” 以“ set” 开头, 还能使用任何其他命名协议? 例如, < code> updateAbc

如有可能,请尽量提供参考链接,以便阅读更多内容。

问题回答

这只是一个命名协议 你可以打破, 使用任何名称。 在反应方面没有限制 。

  const [abc, setAbc] = useState("")
  const [abc, juseSet] = useState("")
  const [abc, updateAbc] = useState("")
  const [abc, change] = useState("")
  const [abc, whatever] = useState("")

以下是"https://react.dev/learn/state-a-conductions-memory#anatomy-of-usestate" Rel=“不跟随 noreferrer">react docs 如何描述它:

常规是将这对配对命名为 Const [ something, set something, somethings] 。 您可以给它命名任何您喜欢的名字, 但常规让项目之间更容易理解 。





相关问题
How to use one react app into another react app?

I have two react apps, parent app and child app. and child app have an hash router. I have build the child app using npm run build, It creates build folder. That build folder moved into inside the ...

how to get selected value in Ant Design

I want to print the selected value, and below is my option list: const vesselName = [ { value: 0 , label: ALBIDDA , }, { value: 1 , label: ALRUMEILA , }, { value: 2 ,...

How to add a <br> tag in reactjs between two strings?

I am using react. I want to add a line break <br> between strings No results and Please try another search term. . I have tried No results.<br>Please try another search term. but ...

热门标签