When I have a react hook and inside of it I want to define a function in it, would I better use(当我有一个反应钩子并在其中时,我想在其中定义一个函数,我最好使用)
useEffect(() => {
//...
function handler() {}
//...
}, []);
or the newer const declaration(或较新的const声明)
useEffect(() => {
//...
const handler = () => {}
//...
}, []);
Are both exactly equivalent or are there differences in how Javascript handles these things?(两者完全相同还是Javascript处理这些事情的方式不同?)
If I define a const, it's only valid within the current scope, while defining a function would be valid elsewhere, is this true?(如果我定义一个const,则它仅在当前范围内有效,而定义一个函数在其他地方将有效,这是真的吗?)
Does react need the functions accessible in different scopes or are they staying local in the current hook scope?(React是否需要在不同作用域中可访问的功能,还是在当前的钩子作用域中保持局部功能?)
ask by Supertyp translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…