How to get my post in conduit.productionready.io (fake api)

Viewed 357

I'm doing a crud test with the article api provided by [https://conduit.productionready.io/api/articles]

I want to do crud test with my article with my account. [https://demo.productionready.io/#/]

Now I've inserted a jwt token into config / headers, using axios to import.

Please tell me how to get my list from conduit.productionready.io!

async function fetchPosts(func: any){
        await axios.get('https://conduit.productionready.io/api/articles', {
            headers: {
                authorization: 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6MTQwMTA4LCJ1c2VybmFtZSI6InlldW1teSIsImV4cCI6MTYxNzU0NTI1OH0.jn5NLpUP15nV56W19OJpywcaPf9ALJRGVOQ_wC_ept8'
            }
        })
            .then(func)
            .catch(console.log);
    }
    
    const loadPosts = ((posts: Post[], func: any)=>{
        if (posts.length === 0) fetchPosts(func);
    })
    
    export default function PostListView() {
        const initState: Post[] = [];
        const [posts, setPosts] = useState(initState);
    
        if (!posts) return <div> Loading... </div>;
        // eslint-disable-next-line react-hooks/rules-of-hooks
        useEffect(()=>{
            loadPosts(posts,
                (response: AxiosResponse)=>{
                setPosts(response.data.articles);
                }
            )
        }, [])
        // @ts-ignore
        return (
            <div
                id="PostListView"
                style={{display: 'flex', flexDirection: 'column', justifyContent: 'center', alignItems: 'center'}}>
                {posts.map(post => <PostCard key={post.createdAt} post={post} /> )}
            </div>
        );
    }
0 Answers
Related