Skip to content

Instantly share code, notes, and snippets.

@cyberfly
Last active May 20, 2022 03:15
Show Gist options
  • Select an option

  • Save cyberfly/25436753c31da19aec267a7997176e80 to your computer and use it in GitHub Desktop.

Select an option

Save cyberfly/25436753c31da19aec267a7997176e80 to your computer and use it in GitHub Desktop.
import React, { useState, useEffect } from "react";
import GenerateCounter from "../components/GenerateCounter";
import { generateArticle } from "../services/ArticleService";
const Generate = () => {
const [count, setCount] = useState(1);
const updateCount = new_count => {
setCount(new_count);
};
return (
<>
<div className="my-10">
<GenerateCounter count={count} updateCount={updateCount}></GenerateCounter>
</div>
</>
);
};
export default Generate;
import React, { useState, useEffect } from "react";
const GenerateCounter = ({ count, updateCount, ...restProps }) => {
const handleClick = (e) => {
let new_count = count + 1;
updateCount(new_count);
};
return (
<>
<button
onClick={(e) => handleCounterClick(e)}
type="button"
className="text-3xl border p-4"
>
Plus
</button>
</>
);
};
export default GenerateCounter;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment