React의 ToDo 목록에 대한 튜토리얼을 통해 다음 오류가 발생했습니다. 나는 상당한 시간을 보냈으며 실수를 찾을 수 없습니다. 오류 및 구성 요소의 코드와이 (문제는이 커밋에 나타납니다) 코스의 repo에 대한 코드입니다 :고유 한 "키"오류 응답
https://github.com/andrewjmead/react-course-todo-app/commit/0521f151705f78cb9f8d69262eb093f1431cb9ca
어떤 도움이 많이 감사합니다.
경고 : 배열이나 반복기의 각 하위에는 고유 한 "키"소품이 있어야합니다. TodoList
의 렌더링 방법을 확인하십시오. 자세한 정보는 fb.me/react-warning-keys를 참조하십시오. I는 todo.id
따라서 undefined
고유하지 내기
var uuid = require('uuid');
var moment = require('moment');
export var searchTextReducer = (state = '', action) => {
switch (action.type) {
case 'SET_SEARCH_TEXT':
return action.searchText;
default:
return state;
};
};
export var showCompletedReducer = (state = false, action) => {
switch (action.type) {
case 'TOGGLE_SHOW_COMPLETED':
return !state;
default:
return state;
};
};
export var todosReducer = (state = [], action) => {
switch(action.type) {
case 'ADD_TODO':
return [
...state,
{
text: action.text,
id: uuid(),
completed: false,
createdAt: moment().unix(),
completedAt: undefined
}
];
case 'TOGGLE_TODO':
return state.map((todo) => {
if(todo.id === action.id) {
var nextCompleted = !todo.completed;
return {
...todo,
completed: nextCompleted,
completedAt: nextCompleted ? moment().unix() : undefined
};
} else {
return todo;
}
});
case 'ADD_TODOS':
return [
...state,
...action.todos
];
default:
return state;
}
};
Webpack:
var webpack = require('webpack');
module.exports = {
entry: [
'script!jquery/dist/jquery.min.js',
'script!foundation-sites/dist/js/foundation.min.js',
'./app/app.jsx'
],
externals: {
jquery: 'jQuery'
},
plugins: [
new webpack.ProvidePlugin({
'$': 'jquery',
'jQuery': 'jquery'
})
],
output: {
path: __dirname,
filename: './public/bundle.js'
},
resolve: {
root: __dirname,
modulesDirectories: [
'node_modules',
'./app/components',
'./app/api'
],
alias: {
applicationStyles: 'app/styles/app.scss',
actions: 'app/actions/actions.jsx',
reducers: 'app/reducers/reducers.jsx',
configureStore: 'app/store/configureStore.jsx'
},
extensions: ['', '.js', '.jsx']
},
module: {
loaders: [
{
loader: 'babel-loader',
query: {
presets: ['react', 'es2015']
},
test: /\.jsx?$/,
exclude: /(node_modules|bower_components)/
}
]
},
devtool: 'cheap-module-eval-source-map'
};
당신의 감속비/행동 파일을 공유 할 수 있습니까? – Joe
거기에 게시판을 편집했습니다 – Smithy
확산 된 운영자 오류가 발생하면 webpack에 babel stage-0이 누락 된 것 같습니다. npm install --save-dev babel-preset-stage-0을 설치하십시오. – Joe