728x90 javascript6 The left-hand side of an assignment expression may not be an optional property access 오류 해결 이 오류는 JavaScript 및 TypeScript에서 발생하는데, 객체의 선택적 프로퍼티에 값을 할당하려고 할 때 발생합니다. 선택적 프로퍼티 접근은 ?. 연산자를 사용하여 수행되며, 객체가 undefined 또는 null인 경우 프로퍼티 접근을 방지하고 undefined를 반환합니다. 예를 들어, 다음 코드에서 오류가 발생합니다. const obj = { nested: { property: "value", }, }; obj.nested?.property = "newValue"; 이 경우, 선택적 프로퍼티 접근을 사용하지 않고 객체 프로퍼티에 값을 할당하려면 다음과 같이 코드를 변경해야 합니다 if (obj.nested) { obj.nested.property = "newValue"; } 또는 더 간.. 2023. 4. 12. useEffect 사용하기 import React, { useEffect } from 'react'; import { useRouter } from 'next/router'; function Example({ name }) { const router = useRouter(); useEffect(() => { // router.isReady 또는 name이 변경될 때마다 실행됩니다. console.log('router.isReady or name has changed:', router.isReady, name); // cleanup 함수를 반환할 수도 있습니다. 이 함수는 다음 실행 전에 호출됩니다. return () => { console.log('Cleaning up:', router.isReady, name); }; }, [r.. 2023. 4. 5. 이전 1 2 다음 728x90