エラーの解消方法を知りたい
最近、reactを勉強し始めた初学者です。
インポートかエクスポートがうまくできないので、どうすれば良いか知りたいです。
Failed to compile ./src/reducers/index.js Attempted import error: './userReducer' does not contain a default export (imported as 'userReducer').
react
1// src/reducers/index.js 2// src/reducers/userReducer.js 3import { combineReducers } from 'redux' 4import userReducer from './userReducer'; 5 6export default combineReducers({ 7 user: userReducer 8});
追記
js
1// src/reducers/postReducer.js 2 3import { FETCH_POSTS, NEW_POST, SING_IN, SING_OUT } from '../types'; 4import initialState from './initialState'; 5 6export default function posts(state = initialState, action) { 7 switch (action.type) { 8 case FETCH_POSTS: 9 return { 10 ...state, 11 items: action.payload 12 }; 13 case NEW_POST: 14 return { 15 ...state, 16 item: action.payload 17 }; 18 default: 19 return state; 20 } 21}
js
1// src/reducers/userReducer.js 2import { FETCH_POSTS, NEW_POST, SING_IN, SING_OUT } from '../types'; 3import initialState from './initialState'; 4 5export default function user(state = initialState, action) { 6 switch (action.type) { 7 case SING_IN: 8 return { 9 ...state, 10 ...action.payload 11 }; 12 case SING_OUT: 13 return { 14 ...state, 15 ...action.payload 16 }; 17 default: 18 return state; 19 } 20}
js
1// src/reducers/initialState.js 2 3const initialState = { 4 items: [], 5 item: {}, 6 user: { 7 isSignedIn: false, 8 firstName: "", 9 lastName: "", 10 userId: "", 11 address: { 12 zipCode: "", 13 stateName: "", 14 city: "", 15 line: "", 16 line2: "", 17 buidingName: "" 18 } 19 } 20}; 21 22export default initialState
肝心なファイルの詳細がないという指摘を受けたので、reducerのソースコードとファイルパスを追記させて頂きました。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/10/26 01:23
2020/10/26 04:19