score:1
You should try Redux Toolkit, it saves a lot of time in creating the actions and reducers. Also read about createAsyncThunk for fetching data using and RESTful API. Try this tutorial https://www.softkraft.co/how-to-setup-slices-with-redux-toolkit/ And take a look into the documentation https://redux-toolkit.js.org/api/createAsyncThunk
score:1
You're not referencing anything from your redux store in App.js. To call data from the store, you need to use the useSelecter hook.
And I'm assuming your code is incomplete? If not the useEffect hook is redundant here. So are the useDispatch and useState hooks.
Below is the edited code with redux toolkit. It is the recommended library for using redux currently. I've forgotten what I learned about actions and reducers.
I'm not sure how does your initial data in redux store looks like, but here goes.
App.js
import React from "react";
import { useSelector } from "react-redux";
import { getData } from "./actions/actions";
const App = () => {
const {data} = useSelecter((state) => state)
const dispatch = useDispatch();
useEffect(() => {
fetch("http://localhost:5000/routes")
.then(res => {
return res.json();
})
.then(data => {
// dispatch to store
})
}, []);
return (
<div className="App">
<h1>Hello</h1>
{/* {posts.map((post)=>(
<h1>{post.title}</h1>
))} */}
{/* Trying to display title and description */}
<h1>{data.title}</h1>
<h1>{data.description}</h1>
</div>
);
};
export default App;
Source: stackoverflow.com
Related Query
- How do I display data from api using react and redux
- How can I cache data that I already requested and access it from the store using React and Redux Toolkit
- How to fetch and display data from Express API to a React app?
- How to fetch data from a custom React hook (API) with onClick and display it in a Div using TypeScript?
- How to load and display data with React from an API running on localhost
- Display data from API using react component and useEffect
- React App: How to display data from api using fetch
- How to set state at the server for data from API using react redux
- How to display POST API data containing string using fetch and map function in React
- How can i get a single data from local api using react and redux?
- How to concatenate URL and string, and get data from API at click a button using axios in REACT JS
- How to delete data from database by using React js and REST API
- How to properly fetch data from several API calls and display it to the DOM in React
- How to execute store.unsubscribe from useEffect using React hooks and Redux
- How do I access data returned from an axios get to display on a web page using react js?
- How to make the API call and display it in React JS using React Table and Axios?
- How to redirect to 404 if no data from external API (universal React + Redux app)?
- REACT JS How can I display my fetched API data from onClick?
- How to retrieve data from Redux store using functional components and avoiding useSelector & useDispatch
- How to Read image data from API and render in React Component
- How to send data from react and use the request body in express, using Axios?
- How to fetch and display data from json file in react typscript
- How do I correctly add data from multiple endpoints called inside useEffect to the state object using React Hooks and Context API?
- How to Assign react redux state api get data using axios
- How to display data from api in React
- How to filter JSON data from API and setState in React
- React Redux how to pass data from input to rest api
- How to display data from the api in react
- How to get the data from Redux store using class components in React
- How do I stop state store data from accumulating in a redux component every time I navigate to it using react router
More Query from same tag
- Console log output of element in a React app
- Draft js. Persist EditorContent to database
- Changing specific index of an array in state instead of all of my state object
- Strange Unresolved dependencies to 'vscode' when wrapping monaco-editor and monaco-languageclient as a react component
- I want to use Gatsby.js to get RSS data from GraphQL. GraphiQL or I am able to get it successfully
- How to test component that is wrapped in HOC?
- React Hook Form using Controller, yup and Material UI - validation issue
- React : best way to Import / Export
- mock fetch request with fetch-mock using headers
- How does @inject of Mobx map stores?
- Ionic react app showing blank page after first state change
- Update single element of the array in redux state
- How do I sort specific questions to a specific section?
- Callback function within map
- ReactJS internationalization
- KendoReact Chart panning issue for ChartSeriesItem with map function
- Does React Native utilize a 'virtual DOM'?
- Modifying default configuration for react app
- React Materials-UI disable a button in a handler
- React component view does not get update
- Webpack throws error when trying to build JSX
- How to do animations with React and Immutable.js?
- Cannot get window.location.origin in React return
- setting state in functional component. (object in array that is in object)
- Getting NextJS Image Component & @svgr/webpack to play nicely together
- create array for each same month in javascript
- webpack-cli Running multiple commands at the same time is not possible
- Runtime environment variable for react app
- Publish a react component to npm and reuse it
- How to add a map in to get the data in the firestore?