Skip to content

Instantly share code, notes, and snippets.

@DJanoskova
Last active September 22, 2021 17:17
Show Gist options
  • Select an option

  • Save DJanoskova/a5ef756029d3462b06cc2766fdccce63 to your computer and use it in GitHub Desktop.

Select an option

Save DJanoskova/a5ef756029d3462b06cc2766fdccce63 to your computer and use it in GitHub Desktop.
import React, { useState, useEffect, useCalllback } from 'react'
import { fetchUserAction } from '../api/actions.js'
const UserContainer = () => {
const [user, setUser] = useState(null);
const handleUserFetch = useCalllback(async () => {
const result = await fetchUserAction();
setUser(result);
}, []);
useEffect(() => {
handleUserFetch();
}, [handleUserFetch]);
if (!user) return <p>No data available.</p>
return <UserCard data={user} />
};
@lgersman
Copy link

Correct me when I'm wrong ...

  • Line 8 should be const handleUserFetch = useCallback(async () => {

  • Line 19 should be return <UserCard />

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment