You looking for useSelector hook.

Do not use store.getState() in functional component. Also, you do not need to connect functions components, use useDispatch hook.

Getting values from store will be like this:

const todos = useSelector(store => store.items);
Answer from Anton Neverov on Stack Overflow
🌐
Medium
unnikrishnand.medium.com › implementation-of-react-redux-data-store-with-react-hooks-and-functional-components-80082fbd2597
Implementation of React Redux data store with React Hooks and functional components | by Unni Krishnan D | Medium
February 22, 2021 - What im trying to achieve is to get a list of users through an API call , store it in store and retrieve the data in one of the component. ... import React from 'react';import ReactDOM from 'react-dom';import './index.css';import { createStore } from 'redux';import { Provider } from 'react-redux';import UserComponent from './App';import rootReducers from './reducers';const store = createStore(rootReducers)ReactDOM.render(<Provider store={store}><UserComponent /></Provider>,document.getElementById('root')) Usercomponent : Our functional component where we are getting this data.
Top answer
1 of 2
4

You looking for useSelector hook.

Do not use store.getState() in functional component. Also, you do not need to connect functions components, use useDispatch hook.

Getting values from store will be like this:

const todos = useSelector(store => store.items);
2 of 2
1

It's very odd they (code bootcamp) would require you to use a function component and then not allow you to use the React hooks that make the function components so appealing. No worries, you can still use the older connect Higher Order Component to inject your redux state and dispatchable actions into the props passed to the component.

You've an issue in AddToDo component. You are passing the mapDispatchToProps to the connect HOC where the mapStateToProps callback would be passed. You also aren't using the injected addTodo action you just mapped. You almost won't ever need to access the store object directly to dispatch actions, use the React components/hooks.

export function AddTodo() {
  const [state, setState] = React.useState({
    title:"",
    description:"",
    place:"",
    date:"",
  });

  function handleChange(e) { 
    const { value } = e.target;
    setState(prevState => ({ // <-- use functional state update
      ...prevState,
      [e.target.name]:value
    }));
  }

  function handleSubmit(e) {
    e.preventDefault();
    this.props.addTodo({ // <-- addTodo action injected into props
      place:state.place,
      title:state.title,
      date:state.date,
      description:state.description
    });
    setState({
      title:"",
      description:"",
      place:"",
      date:"",
    });
  }

  return (
    <div className="todoContainer">
      ...
    </div>
  )
};

const mapDispatchToProps = {
  addTodo,
}

export default connect(null, mapDispatchToProps)(AddTodo); // <-- mapStateToProps is null

In Todos component, your todos state is an array, so you likely want to map it to JSX. Remember to destructure the passed props. Since you didn't share your reducers or how you combine your reducers I'm going to assume there is just one reducer for todos located at the state root.

[update] Since it seems your rootReducer is just your todos reducer function and I don't see where combineReducers is used to build a more complex state tree, state IS your todos array state you are trying to pass to Todos component. [/update]

function Todos({ todos }) {
  return (
    <div className="todoDetail">
      {todos.map((todo) => (
        <h4 key={todo.id}>{todo.title}</h4>
      ))}  
    </div>
  )
};
  
function mapStateToProps(state) {
  return {
    todos: state, // <-- state is todos array
  };
}

export default connect(mapStateToProps)(Todos);
🌐
Better Programming
betterprogramming.pub › build-a-redux-like-store-with-react-context-hooks-234e3774495f
How To Build a Redux-Like Store With React Context and Hooks | by Pubudu Ranasinghe 🦄 | Better Programming
November 6, 2019 - Following the same pattern, you can create new ContextProviders, wrap your application with it, and then use a custom useContext Hook anywhere in your component hierarchy to use it as a store.
🌐
How-To Geek
howtogeek.com › home › how to use state in functional react components
How to Use State in Functional React Components
March 31, 2021 - You could revert to a class-like system, using a single object stored in state: ... property to its new value. It's important you create a new object, instead of directly mutating the existing object, so React's state ...
🌐
Medium
rajeshnaroth.medium.com › component-state-management-in-react-functional-components-with-hooks-e7c412c05e71
Component State Management in React Functional Components with hooks
June 25, 2020 - It is not possible to persist state in local variables as these are initialized every time the function is evaluated. Thus to maintain state inside the function, React provides several hooks: useState() hook allows you create and mange ...
Find elsewhere
🌐
React Redux
react-redux.js.org › accessing the store
Accessing the Store | React Redux
June 11, 2024 - Could not find "store" in the context of "Connect(MyComponent)". Either wrap the root component in a <Provider>, or pass a custom React context provider to <Provider> and the corresponding React context consumer to Connect(Todo) in connect options.
🌐
freeCodeCamp
freecodecamp.org › news › how-to-manage-state-in-a-react-app
How to Manage State in a React App – With Hooks, Redux, and More
September 11, 2024 - To create a store, we import the createStore function and pass it a reducer as input. Know that you can also combine different reducers and pass it to the same store in case you'd like to separate concerns into different reducers.
🌐
DEV Community
dev.to › ruppysuppy › next-gen-way-to-connect-redux-store-to-react-component-5b57
Next-Gen Way to Connect Redux Store to React Component - DEV Community
March 1, 2025 - Getting Redux Store Data has been simplified several folds with the introduction of useSelector Hook. You can now use the hook to directly get the store data inside the React Component...
🌐
DEV Community
dev.to › sarioglu › how-to-store-a-function-using-react-usestate-4ffh
How to store a function using React.useState - DEV Community
September 9, 2020 - However when I run it, I found out that the callback function was invoked immediately. The code seems straightforward enough. But it took a couple of minutes to realize my mistake. It is because update function of useState accepts either a value or a function to return a value: type SetStateAction<S> = S | ((prevState: S) => S); That's why when I passed a function to setMyFunc, React tried to get the return value of callback function by passing prevState to it as an argument.
🌐
Stack Overflow
stackoverflow.com › questions › 68210999 › how-to-make-a-functional-component-store-props-in-react
How to make a functional component store props in React
July 1, 2021 - So currently I am able to pass in props and access what is returned within the same component, but I wanted to redirect to a new page and still be able to access the data within the component the d...
🌐
Medium
medium.com › geekculture › redux-with-reacts-functional-components-272f1008ee69
Redux with React’s Functional Components | by Sean LaFlam | Geek Culture | Medium
June 10, 2021 - This is the standard Redux setup, where we use mapStateToProps to get access to properties on the Redux store available to our component as props, and then dispatch actions to our reducer (also available as props) in order to update those properties. When using Hooks however we need to do things a little differently. The useSelector hook is how we are going to mimic the mapStateToProps function in our component. Start by importing useSelector from ‘react-redux’.
🌐
DigitalOcean
digitalocean.com › community › tutorials › how-to-manage-state-with-hooks-on-react-components
How To Manage State with Hooks on React Components | DigitalOcean
July 14, 2020 - Unlike class-based components, you cannot update several pieces of state with a single function call. Instead, you must call each function individually. This means there is a greater separation of concerns, which helps keep stateful objects focused. Create a function to add an item to the cart and update the total with the price of the item, then add that functionality to the Add button: ... import React, { useState } from 'react'; ...
🌐
Dave Ceddia
daveceddia.com › access-redux-store-outside-react
Access the Redux Store Outside a React Component
If you need to dispatch actions from outside a React component, the same technique will work: import the store, then call store.dispatch(), passing the action you need to dispatch. It works the same as the dispatch function you get from props via react-redux’s connect function.