How can i add redux for sorting. I'm trying to sort using redux for api returning a JSON array. Could someone please help me as i'm new to Redux
import React, { useState, useEffect } from "react"; import Post from "../../Components/Post/Post"; import axios from "axios"; const HomePage = () => { const [posts, setPosts] = useState(""); let config = { Authorization: "3055f8f90fa44bbe8bda05385a20690a" }; const url = "https://newsapi.org/v2/top-headlines?sources=bbc-news"; useEffect(() => { AllPosts(); }, []); const AllPosts = () => { axios .get(`${url}`, { headers: config }) .then((response) => { const allPosts = response.data.articles; console.log(response); setPosts(allPosts); }) .catch((error) => console.error(`Error: ${error}`)); }; return ( <div> <Post className="Posts" posts={posts} /> </div> ); }; export default HomePage;
https://stackoverflow.com/questions/67342814/how-to-use-redux-for-sorting May 01, 2021 at 12:13PM
没有评论:
发表评论