Properties of the State Object in React Redux

I'm curious as to why my state todos were named todo instead of todos in the redux dev tools. Where did that name come from? There is no initial state, which makes me wonder.

I'm currently following a Udemy course by Stephen Grider, but I am working with todos instead of streams for revision.

Why do I have to access it using state.todo instead of state.todos?

Link to My Github Repository

Json server db.json file (api file)


        {
      "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;
      }
    };

actions/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('/');
    };

Answer №1

you have specified the list as todo instead of todos.

If you want to review in sandbox, click here:

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

React Hot Toast useState is unfortunately not exported from the React library

While working on a Next.js project, I encountered an issue when trying to use react-hot-toast. When I attempted to import it into any file, I received the following error message: Error - ./node_modules/react-hot-toast/dist/index.mjs Attempted import erro ...

Leveraging the power of React and Flutter to create Android instant apps and Apple App Clips

Is there any restrictions when it comes to using React and/or Flutter for Android Instant App as well as Apple App Clips? I haven't been able to find much information on this aside from the size limitations (15MB for Android and 10MB for Apple). Fur ...

What separates the functions `useRef` and `createRef` from each other?

As I was delving into the hooks documentation, I came across useRef. Upon examining their example… function TextInputWithFocusButton() { const inputEl = useRef(null); const onButtonClick = () => { // `current` refers to the mounted text inpu ...

How is the purpose of nesting functions within functions achieved in nodejs?

Take a look at this example: var tools1 = require('../tools/tools1'); var test_func = function(arg1, arg2, arg3) { var local_var_1 = "lc1"; var local_var_2 = "lc2"; return function(data) { var result = tools1.doSth(local_va ...

Vue.js: click event does not trigger transform animation

I am facing a challenge with rotating an arrow icon within a dropdown menu. Despite my efforts, the rotation does not synchronize with the appearance of the dropdown menu. Here is the Vue component code snippet: <nav> <section class= ...

Accessing a key from an AJAX JSON response and applying it within a .each() loop in jQuery

I'm struggling with a seemingly simple task that I just can't seem to get right. My goal is to convert multiple text inputs into select fields using AJAX and jQuery. Everything works smoothly, except when trying to make the $.each function dynam ...

What is the method to store anchor text in a Session variable?

I'm currently working on a project where I've linked multiple pdf files in the master page. When clicking the anchor, the page redirects to the specified location and displays the pdf in an iframe. Now, I want the text within the anchor tag to be ...

Error message: The CustomEvent is not properly defined in the NextJS project, causing a Reference

I encountered an error: ReferenceError: CustomEvent is not defined. I am aware that CustomEvent is only available on the client side (browser), but I am attempting to utilize this function as an event: const mouseEnterHandler = () => { eventDispatc ...

Refresh a javascript file using the power of jquery

I have created a PHP file that displays a session meter in Joomla's frontend using JavaScript. Additionally, I have another PHP file that shows user details and reloads using jQuery. My goal is to make the JavaScript session meter also reload when the ...

Acquire the S3 URL link for the uploaded file upon completion of the file upload process

Is there a way to securely upload and generate a public Amazon S3 URL for a PDF file when a user clicks on a specific link? I'd like to avoid exposing the actual link to the user by uploading it to S3. Here's a sample code snippet: module.expo ...

Is there a method to refresh the image in the template?

I am currently working on generating various images using canvas. Is there a way to display these images in real-time on my main.pug template without having to reload the page every time an image changes? const Canvas = require('canvas') , Ima ...

NextJS: Error - Unable to locate module 'fs'

Attempting to load Markdown files stored in the /legal directory, I am utilizing this code. Since loading these files requires server-side processing, I have implemented getStaticProps. Based on my research, this is where I should be able to utilize fs. Ho ...

Choose a division of an element within an embedded frame

Two different pages on the same website, Home.html and Page2.html. Home.html contains the following code: <html> <iframe id="one" src="page2.html" style="display:none"></iframe> <div id="container"> <h1& ...

Vuetify offers a convenient solution for implementing multiple buttons in a Vue

My search bar retrieves data from an API query in the following format: Data: [[id, datafield1, datafield2],[id, datafield1, datafield2],...] I wish to include an on/off button for each row of the data, with each button having its own independent state. ...

Transmitted a file from React to Node but received an empty object

After retrieving image data, I am sending this data to the server and checking if it exists using console.log. const [fileData, setFileData] = useState(""); console.log("fileData:", fileData); const getFile = (e: any) => { setFileData(e.target.fi ...

Encountering a problem with GraphQL API fetching in Next.js: receiving the error message "React functionality 'useContext' is not supported in this environment."

Currently, I have developed a Next.js 14.2.3 application with a GraphQL API endpoint (which I replaced with localhost for StackOverflow). For data fetching, I am utilizing "@apollo/client": "^3.10.3" and "graphql": "^16.8.1". The product page path has been ...

Updating dynamic parameter in a NextJS 13 application router: A complete guide

In my route user/[userId]/forms, I have a layout.tsx that includes a Select/Dropdown menu. The dropdown menu has options with values representing different form IDs. When the user selects an item from the dropdown, I want to navigate to user/[userId]/form ...

Tips for including a new class in an HTML element

My goal is to add a specific class to an HTML tag, if that tag exists. This is the code I have attempted: <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>index</title> <style> ...

The connection between two arrays remains intact even after using the .push() method in JavaScript or Vue.js

I need help setting up two arrays containing dates. The first array should have the dates in string format, while the second array should contain the same dates but as date objects. methods: { test() { let employments = [ { begin: ...

Guide on retrieving POST data in sveltekit

Hello, I'm new to sveltekit and I am trying to fetch post data in sveltekit using a POST request. Currently, I am utilizing axios to send the post data. const request = await axios .post("/api/user", { username, email, ...