11. Hooks – Reusability, Readability, and a Different Mental Model
Activity 11.01: Creating a Reusable Counter
Solution:
- Start off by creating a new React project, which we will call counter-hooks, start the project, and take a look at the browser window that should have opened for you automatically:
$ npx create-react-app counter-hooks $ cd counter-hooks $ yarn start
- Delete
src/logo.svg
. - Replace the contents of
src/App.css
with the following:body { Â Â margin: 20px; } button { Â Â width: 200px; Â Â height: 50px; Â Â background: #4444ff; Â Â color: white; Â Â font-weight: bold; Â Â border: none; Â Â cursor: pointer; Â Â margin: 5px;Â Â }
- Replace the contents of
src/App.js
with the following:import React from "react"; import "./App.css"; const App = () => ( Â Â <div className="App"> Â Â <h1>Counter</h1>...