亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

React Redux 狀態對象屬性

React Redux 狀態對象屬性

九州編程 2021-06-16 18:19:30
我想知道為什么我的狀態 todos在 redux 開發工具中命名為todo而不是todos .. 這個名字是從哪里來的?沒有初始狀態..我想知道..我正在關注Stephen Grider udemy 課程,但使用待辦事項而不是流作為修訂為什么我必須回到它state.todo不state.todos?Jsson 服務器 db.json 文件(api 文件)        {      "todos": [        {          "title": "lorem ipsum ",          "description": "lorem ipsum",          "id": 4        }      ]    }todoReducer.js        import _ from 'lodash';    import {      CREATE_TODO,      EDIT_TODO,      FETCH_TODO,      FETCH_TODOS,      DELETE_TODO    } from '../actions/types';    export default (state = {}, action) => {      switch (action.type) {        case FETCH_TODOS:          return { ...state, ..._.mapKeys(action.payload, 'id') };        case CREATE_TODO:        case FETCH_TODO:        case EDIT_TODO:          return { ...state, [action.payload.id]: action.payload };        case DELETE_TODO:          return _.omit(state, action.payload);        default:          return state;      }    };動作/ index.js        import todos from '../apis/todos';    import history from '../history';    import {      SIGN_IN,      SIGN_OUT,      CREATE_TODO,      EDIT_TODO,      FETCH_TODO,      FETCH_TODOS,      DELETE_TODO    } from './types';    export const signIn = userId => {      return { type: SIGN_IN, payload: userId };    };    export const signOut = () => {      return { type: SIGN_OUT };    };    export const fetchTodos = () => async dispatch => {      const response = await todos.get('/todos');      dispatch({ type: FETCH_TODOS, payload: response.data });    };    export const createTodo = formValues => async dispatch => {      const response = await todos.post('/todos', formValues);      dispatch({ type: CREATE_TODO, payload: response.data });      history.push('/');    };
查看完整描述

1 回答

  • 1 回答
  • 0 關注
  • 118 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號