Skip to content

Instantly share code, notes, and snippets.

@Lahirutech
Created December 14, 2021 17:59
Show Gist options
  • Select an option

  • Save Lahirutech/82180b316189b053385a72b78d3af3fd to your computer and use it in GitHub Desktop.

Select an option

Save Lahirutech/82180b316189b053385a72b78d3af3fd to your computer and use it in GitHub Desktop.
import React, { useContext } from "react";
import { CountContext } from "../App";
function ComponentA() {
const countContext = useContext(CountContext);
return (
<div>
Home page cart:{countContext.countState}
<button onClick={() => countContext.countDispatch("increment")}>
Add Item
</button>
<button onClick={() => countContext.countDispatch("decrement")}>
Remove Item
</button>
<button onClick={() => countContext.countDispatch("reset")}>Clear</button>
</div>
);
}
export default ComponentA;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment