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/984dd100bedffb069a4d120ef3e1ffaf to your computer and use it in GitHub Desktop.
Save codegagan/984dd100bedffb069a4d120ef3e1ffaf to your computer and use it in GitHub Desktop.
Test with multiple useState implementations
import React, { useState } from "react";
export default function MultipleStatesComponent() {
const [dataLength, setDataLength] = useState(0);
const [loading, setLoading] = useState(false);
const [text, setText] = useState("");
const handleButtonOne = () => {
setDataLength(10);
};
const handleButtonTwo = () => {
setLoading(true);
setText("text set by button");
};
return (
<div>
<h1>Set states with buttons</h1>
<button onClick={handleButtonOne}> Set length </button>
<button onClick={handleButtonTwo}> Click to set values </button>
</div>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment