如果像这样的代码通过 的useEffect依赖关系重新渲染,
// ...
const Test = () => {
// ...
const value1 = "test1"
const func1 = () => {
// do something1
}
useEffect(() => {
const value2 = "test2"
const func2 = () => {
// do something2
}
}, [sth])
return (
// ...
)
}Run Code Online (Sandbox Code Playgroud)
value1&&&value2重新分配内存吗func1?func2
我很好奇,与优化有关。
下面是我的代码,
我不知道为什么 console.log('are you running?') 没有显示,
我的代码有什么问题吗?
我尝试添加自定义语言检测器..
import i18n, { LanguageDetectorModule } from 'i18next';
import { initReactI18next } from 'react-i18next';
import resources from './i18n_resources.json';
import { isLocalhost } from '@/common/detect_utils';
import { detectLanguage } from '.';
const languageDetector: LanguageDetectorModule = {
type: 'languageDetector',
detect: () => {
console.log('are you running?');
return 'en';
},
init: () => {},
cacheUserLanguage: () => {},
};
i18n
.use(initReactI18next)
.use(languageDetector)
.init({
resources,
lng: 'ko',
fallbackLng: 'en',
keySeparator: false,
debug: isLocalhost,
interpolation: {
escapeValue: false, …Run Code Online (Sandbox Code Playgroud) 我是JavaScript的初学者。
我真的很好奇代码如何工作.. !!
请问有人可以解释下面的代码如何工作吗?
看起来与 'abc'.toUpperCase();
'aaa'['toUpperCase'].apply('abc'); // ABC
Run Code Online (Sandbox Code Playgroud)