November 11, 2022
Warning: Encountered two children with the same key,
0. Keys should be unique so that components maintain their identity across updates. Non-unique keys may cause children to be duplicated and/or omitted — the behavior is unsupported and could change in a future version.
Next.js로 프로젝트를 생성하면 자동으로 next.config.js 파일이 생성되고, 아래처럼 설정된다.
/** @type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: true,
};
module.exports = nextConfig;여기서 reactStrictMode를 false로 해주면 된다.
/** @type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: false,
};
module.exports = nextConfig;그러나 리액트 공식 문서에서는 StrictMode가 아래와 같은 문제를 찾아준다고 적혀있으며, StrictMode는 개발 모드에서만 활성화되기 때문에, 프로덕션 빌드 때는 문제가 없다고 한다.
push를 통해 입력했기 때문에 발생했던 문제였다. 그래서 push 대신에 마지막 index + 1 위치에 값을 넣는 방식으로 해결했다.