Skip to content

Instantly share code, notes, and snippets.

@codegagan
Last active September 6, 2020 14:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codegagan/8af04391196bde64b062f0ddca94159b to your computer and use it in GitHub Desktop.
Save codegagan/8af04391196bde64b062f0ddca94159b to your computer and use it in GitHub Desktop.
Test the behavior defined in useEffect
import React, { useState, useEffect } from "react";
export default function EffectComponent() {
const [dataSize, setDataSize] = useState(0);
const loadData = () => {
const dataFromApi = ['a', 'b', 'c'];
setDataSize(dataFromApi.length);
};
useEffect(loadData, []);
return (
<div>
<h1>Data size: {dataSize}</h1>
</div>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment