React keywords: createContext, useContext, useEffect, useReducer

Project overview:

Project shows: The useReducer hook is used for the first time, along with the useContext hook. useReducer is very similar to useState, but it lets you move the state update logic from event handlers (useEffect) into a single function outside of your component.

–  Initially the

   function QuizProvider({ children}) {

defines:

 const [ { variables… }, dispatch, ] = useReducer(reducer, initialState);

The reducer uses the:

   const initialState = {
questions: [],
// ‘loading’, ‘error’, ‘ready’, ‘active’, ‘finished’
status: “loading”,
index: 0,
answer: null,
points: 0,
highscore: 0,
secondsRemaining: null,
};

to initialize the state object. Any state update logic is performed inside the:

function reducer(state, action) {
  switch (action.type) {
    case “dataReceived”:
      return {
        state,
        questions: action.payload,
        status: “ready”,
      };
    …
    default:
      throw new Error(“Action unkonwn”);
  }
}

The reducer method is called through the dispatch method.

As an example, after the state is initialized in the useReducer definition, the quiz questions are loaded into the state object by:

 useEffect(function () {
dispatch({ type: “dataReceived”, payload: testQuestions });
}, []);

which is called when the <QuizProvider> mounts.

The dispatch is called by each component when necessary. As an example, the <StartScreen /> component will call the dispatch reducer method when its button is clicked on:

 function StartScreen() {
const { numQuestions, dispatch } = useQuiz();

  return (
<div className=”start”>
<h2>Welcome to The React Quiz!</h2>
<h3>{numQuestions} questions to test your React mastery</h3>
<button className=”btn btn-ui” onClick={() => dispatch({ type: “start” })}>
Let’s start
</button>
</div>
);
}

and the reducer acts on the “start” action as:

case “start”:
      return {
        state,
        status: “active”,
        secondsRemaining: state.questions.length * SECS_PER_QUESTION,

      };

by changing the state.status and state.secondsRemaining variables.

Code:

<!DOCTYPE html>
<html lang=“en”>
  <head>
    <meta charset=“utf-8” />
    <link rel=“icon” href=“%PUBLIC_URL%/favicon.ico” />
    <meta name=“viewport” content=“width=device-width, initial-scale=1” />
    <meta name=“theme-color” content=“#000000” />
    <meta
      name=“description”
      content=“Web site created using create-react-app”
    />
    <link rel=“apple-touch-icon” href=“%PUBLIC_URL%/logo192.png” />
    <!–
      manifest.json provides metadata used when your web app is installed on a
      user’s mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
    –>
    <link rel=“manifest” href=“%PUBLIC_URL%/manifest.json” />
    <!–
      Notice the use of %PUBLIC_URL% in the tags above.
      It will be replaced with the URL of the `public` folder during the build.
      Only files inside the `public` folder can be referenced from the HTML.

      Unlike “/favicon.ico” or “favicon.ico”, “%PUBLIC_URL%/favicon.ico” will
      work correctly both with client-side routing and a non-root public URL.
      Learn how to configure a non-root public URL by running `npm run build`.
    –>
    <title>The React Quiz</title>
  </head>
  <body>
    <noscript>You need to enable JavaScript to run this app.</noscript>
    <div id=“root”></div>
    <!–
      This HTML file is a template.
      If you open it directly in the browser, you will see an empty page.

      You can add webfonts, meta tags, or analytics to this file.
      The build step will place the bundled scripts into the <body> tag.

      To begin the development, run `npm start` or `yarn start`.
      To create a production bundle, use `npm run build` or `yarn build`.
    –>
  </body>
</html>
import React from “react”;
import ReactDOM from “react-dom/client”;
import “./index.css”;
import App from “./components/App”;
import { QuizProvider } from “./contexts/QuizContext”;

const root = ReactDOM.createRoot(document.getElementById(“root”));
root.render(
  <React.StrictMode>
    <QuizProvider>
      <App />
    </QuizProvider>
  </React.StrictMode>
);
import { useReducer } from “react”;

const initialState = { count: 0, step: 1 };

function reducer(state, action) {
  console.log(state, action);

  switch (action.type) {
    case “dec”:
      return { state, count: state.count state.step };
    case “inc”:
      return { state, count: state.count + state.step };
    case “setCount”:
      return { state, count: action.payload };
    case “setStep”:
      return { state, step: action.payload };
    case “reset”:
      return initialState;
    default:
      throw new Error(“Unknown action”);
  }
}

function DateCounter() {
  const [state, dispatch] = useReducer(reducer, initialState);
  const { count, step } = state;

  // This mutates the date object.
  const date = new Date(“june 21 2027”);
  date.setDate(date.getDate() + count);

  const dec = function () {
    dispatch({ type: “dec” });
  };

  const inc = function () {
    dispatch({ type: “inc” });
  };

  const defineCount = function (e) {
    dispatch({ type: “setCount”, payload: Number(e.target.value) });
  };

  const defineStep = function (e) {
    dispatch({ type: “setStep”, payload: Number(e.target.value) });
  };

  const reset = function () {
    dispatch({ type: “reset” });
  };

  return (
    <div className=“counter”>
      <div>
        <input
          type=“range”
          min=“0”
          max=“10”
          value={step}
          onChange={defineStep}
        />
        <span>{step}</span>
      </div>

      <div>
        <button onClick={dec}>-</button>
        <input value={count} onChange={defineCount} />
        <button onClick={inc}>+</button>
      </div>

      <p>{date.toDateString()}</p>

      <div>
        <button onClick={reset}>Reset</button>
      </div>
    </div>
  );
}
export default DateCounter;
function Error() {
  return (
    <p className=“error”>
      <span>💥</span> There was an error fetching questions.
    </p>
  );
}

export default Error;
import Header from “./Header”;
import Main from “./Main”;
import Loader from “./Loader”;
import Error from “./Error”;
import StartScreen from “./StartScreen”;
import Question from “./Question”;
import NextButton from “./NextButton”;
import Progress from “./Progress”;
import FinishScreen from “./FinishScreen”;
import Footer from “./Footer”;
import Timer from “./Timer”;

import { useQuiz } from “../contexts/QuizContext”;

export default function App() {
  const { status } = useQuiz();

  return (
    <div className=“app”>
      <Header />

      <Main>
        {status === “loading” && <Loader />}
        {status === “error” && <Error />}
        {status === “ready” && <StartScreen />}
        {status === “active” && (
          <>
            <Progress />
            <Question />
            <Footer>
              <Timer />
              <NextButton />
            </Footer>
          </>
        )}
        {status === “finished” && <FinishScreen />}
      </Main>
    </div>
  );
}
function Footer({ children }) {
  return <footer>{children}</footer>;
}

export default Footer;
function Header() {
  return (
    <header className=‘app-header’>
      <img src=‘logo512.png’ alt=‘React logo’ />
      <h1>The React Quiz</h1>
    </header>
  );
}

export default Header;
import { useQuiz } from “../contexts/QuizContext”;

function FinishScreen() {
  const { points, maxPossiblePoints, highscore, dispatch } = useQuiz();

  const percentage = (points / maxPossiblePoints) * 100;

  let emoji;
  if (percentage === 100) emoji = “🥇”;
  if (percentage >= 80 && percentage < 100) emoji = “🎉”;
  if (percentage >= 50 && percentage < 80) emoji = “🙃”;
  if (percentage >= 0 && percentage < 50) emoji = “🤨”;
  if (percentage === 0) emoji = “🤦‍♂️”;

  return (
    <>
      <p className=“result”>
        <span>{emoji}</span> You scored <strong>{points}</strong> out of{” “}
        {maxPossiblePoints} ({Math.ceil(percentage)}%)
      </p>
      <p className=“highscore”>(Highscore: {highscore} points)</p>
      <button
        className=“btn btn-ui”
        onClick={() => dispatch({ type: “restart” })}
      >
        Restart quiz
      </button>
    </>
  );
}

export default FinishScreen;
function Main({ children }) {
  return <main className=“main”>{children}</main>;
}

export default Main;
import { useQuiz } from “../contexts/QuizContext”;

function NextButton() {
  const { dispatch, answer, index, numQuestions } = useQuiz();

  if (answer === null) return null;

  if (index < numQuestions 1)
    return (
      <button
        className=“btn btn-ui”
        onClick={() => dispatch({ type: “nextQuestion” })}
      >
        Next
      </button>
    );

  if (index === numQuestions 1)
    return (
      <button
        className=“btn btn-ui”
        onClick={() => dispatch({ type: “finish” })}
      >
        Finish
      </button>
    );
}

export default NextButton;
export default function Loader() {
  return (
    <div className=“loader-container”>
      <div className=“loader”></div>
      <p>Loading questions…</p>
    </div>
  );
}
import { useQuiz } from “../contexts/QuizContext”;

function Progress() {
  const { index, numQuestions, points, maxPossiblePoints, answer } = useQuiz();

  return (
    <header className=“progress”>
      <progress max={numQuestions} value={index + Number(answer !== null)} />

      <p>
        Question <strong>{index + 1}</strong> / {numQuestions}
      </p>

      <p>
        <strong>{points}</strong> / {maxPossiblePoints}
      </p>
    </header>
  );
}

export default Progress;
import { useQuiz } from “../contexts/QuizContext”;

function Options({ question }) {
  const { dispatch, answer } = useQuiz();

  const hasAnswered = answer !== null;

  return (
    <div className=“options”>
      {question.options.map((option, index) => (
        <button
          className={`btn btn-option ${index === answer ? “answer” : “”} ${
            hasAnswered
              ? index === question.correctOption
                ? “correct”
                : “wrong”
              : “”
          }`}
          key={option}
          disabled={hasAnswered}
          onClick={() => dispatch({ type: “newAnswer”, payload: index })}
        >
          {option}
        </button>
      ))}
    </div>
  );
}

export default Options;
import { useQuiz } from “../contexts/QuizContext”;
import Options from “./Options”;

function Question() {
  const { questions, index } = useQuiz();
  const question = questions.at(index);

  //console.log(question);

  return (
    <div>
      <h4>{question.question}</h4>
      <Options question={question} />
    </div>
  );
}

export default Question;
import { useQuiz } from “../contexts/QuizContext”;

function StartScreen() {
  const { numQuestions, dispatch } = useQuiz();

  return (
    <div className=“start”>
      <h2>Welcome to The React Quiz!</h2>
      <h3>{numQuestions} questions to test your React mastery</h3>
      <button
        className=“btn btn-ui”
        onClick={() => dispatch({ type: “start” })}
      >
        Let’s start
      </button>
    </div>
  );
}

export default StartScreen;
import { useEffect } from “react”;
import { useQuiz } from “../contexts/QuizContext”;

function Timer() {
  const { dispatch, secondsRemaining } = useQuiz();

  const mins = Math.floor(secondsRemaining / 60);
  const seconds = secondsRemaining % 60;

  console.log(mins, seconds, secondsRemaining);

  useEffect(
    function () {
      const id = setInterval(function () {
        dispatch({ type: “tick” });
      }, 1000);

      return () => clearInterval(id);
    },
    [dispatch]
  );

  return (
    <div className=“timer”>
      {mins < 10 && “0”}
      {mins}:{seconds < 10 && “0”}
      {seconds}
    </div>
  );
}

export default Timer;
import { createContext, useContext, useEffect, useReducer } from “react”;

const QuizContext = createContext();

const SECS_PER_QUESTION = 30;

const testQuestions = [
  {
    question: “Which is the most popular JavaScript framework?”,
    options: [“Angular”, “React”, “Svelte”, “Vue”],
    correctOption: 1,
    points: 10,
  },
  {
    question: “Which company invented React?”,
    options: [“Google”, “Apple”, “Netflix”, “Facebook”],
    correctOption: 3,
    points: 10,
  },
  {
    question: “What’s the fundamental building block of React apps?”,
    options: [“Components”, “Blocks”, “Elements”, “Effects”],
    correctOption: 0,
    points: 10,
  },
  {
    question:
      “What’s the name of the syntax we use to describe the UI in React components?”,
    options: [“FBJ”, “Babel”, “JSX”, “ES2015”],
    correctOption: 2,
    points: 10,
  },
  {
    question: “How does data flow naturally in React apps?”,
    options: [
      “From parents to children”,
      “From children to parents”,
      “Both ways”,
      “The developers decides”,
    ],
    correctOption: 0,
    points: 10,
  },
  {
    question: “How to pass data into a child component?”,
    options: [“State”, “Props”, “PropTypes”, “Parameters”],
    correctOption: 1,
    points: 10,
  },
  {
    question: “When to use derived state?”,
    options: [
      “Whenever the state should not trigger a re-render”,
      “Whenever the state can be synchronized with an effect”,
      “Whenever the state should be accessible to all components”,
      “Whenever the state can be computed from another state variable”,
    ],
    correctOption: 3,
    points: 30,
  },
  {
    question: “What triggers a UI re-render in React?”,
    options: [
      “Running an effect”,
      “Passing props”,
      “Updating state”,
      “Adding event listeners to DOM elements”,
    ],
    correctOption: 2,
    points: 20,
  },
  {
    question: ‘When do we directly “touch” the DOM in React?’,
    options: [
      “When we need to listen to an event”,
      “When we need to change the UI”,
      “When we need to add styles”,
      “Almost never”,
    ],
    correctOption: 3,
    points: 20,
  },
  {
    question: “In what situation do we use a callback to update state?”,
    options: [
      “When updating the state will be slow”,
      “When the updated state is very data-intensive”,
      “When the state update should happen faster”,
      “When the new state depends on the previous state”,
    ],
    correctOption: 3,
    points: 30,
  },
  {
    question:
      “If we pass a function to useState, when will that function be called?”,
    options: [
      “On each re-render”,
      “Each time we update the state”,
      “Only on the initial render”,
      “The first time we update the state”,
    ],
    correctOption: 2,
    points: 30,
  },
  {
    question:
      “Which hook to use for an API request on the component’s initial render?”,
    options: [“useState”, “useEffect”, “useRef”, “useReducer”],
    correctOption: 1,
    points: 10,
  },
  {
    question: “Which variables should go into the useEffect dependency array?”,
    options: [
      “Usually none”,
      “All our state variables”,
      “All state and props referenced in the effect”,
      “All variables needed for clean up”,
    ],
    correctOption: 2,
    points: 30,
  },
  {
    question: “An effect will always run on the initial render.”,
    options: [
      “True”,
      “It depends on the dependency array”,
      “False”,
      “In depends on the code in the effect”,
    ],
    correctOption: 0,
    points: 30,
  },
  {
    question: “When will an effect run if it doesn’t have a dependency array?”,
    options: [
      “Only when the component mounts”,
      “Only when the component unmounts”,
      “The first time the component re-renders”,
      “Each time the component is re-rendered”,
    ],
    correctOption: 3,
    points: 20,
  },
];

const initialState = {
  questions: [],

  // ‘loading’, ‘error’, ‘ready’, ‘active’, ‘finished’
  status: “loading”,
  index: 0,
  answer: null,
  points: 0,
  highscore: 0,
  secondsRemaining: null,
};

function reducer(state, action) {
  switch (action.type) {
    case “dataReceived”:
      return {
        state,
        questions: action.payload,
        status: “ready”,
      };
    case “dataFailed”:
      return {
        state,
        status: “error”,
      };
    case “start”:
      return {
        state,
        status: “active”,
        secondsRemaining: state.questions.length * SECS_PER_QUESTION,
      };
    case “newAnswer”:
      const question = state.questions.at(state.index);

      return {
        state,
        answer: action.payload,
        points:
          action.payload === question.correctOption
            ? state.points + question.points
            : state.points,
      };
    case “nextQuestion”:
      return { state, index: state.index + 1, answer: null };
    case “finish”:
      return {
        state,
        status: “finished”,
        highscore:
          state.points > state.highscore ? state.points : state.highscore,
      };
    case “restart”:
      return { initialState, questions: state.questions, status: “ready” };

    case “tick”:
      return {
        state,
        secondsRemaining: state.secondsRemaining 1,
        status: state.secondsRemaining === 0 ? “finished” : state.status,
      };

    default:
      throw new Error(“Action unkonwn”);
  }
}

function QuizProvider({ children }) {
  const [
    { questions, status, index, answer, points, highscore, secondsRemaining },
    dispatch,
  ] = useReducer(reducer, initialState);

  const numQuestions = questions.length;
  const maxPossiblePoints = questions.reduce(
    (prev, cur) => prev + cur.points,
    0
  );

  useEffect(function () {
    /*fetch(“http://localhost:9000/questions”)
      .then((res) => res.json())
      .then((data) => dispatch({ type: “dataReceived”, payload: data }))
      .catch((err) => dispatch({ type: “dataFailed” }));*/
    dispatch({ type: “dataReceived”, payload: testQuestions });
  }, []);

  return (
    <QuizContext.Provider
      value={{
        questions,
        status,
        index,
        answer,
        points,
        highscore,
        secondsRemaining,
        numQuestions,
        maxPossiblePoints,

        dispatch,
      }}
    >
      {children}
    </QuizContext.Provider>
  );
}

function useQuiz() {
  const context = useContext(QuizContext);
  if (context === undefined)
    throw new Error(“QuizContext was used outside of the QuizProvider”);
  return context;
}

export { QuizProvider, useQuiz };
:root {
  –color-darkest: #343a40;
  –color-dark: #495057;
  –color-medium: #ced4da;
  –color-light: #f1f3f5;

  –color-theme: #1098ad;
  –color-accent: #ffa94d;
}

@import url(“https://fonts.googleapis.com/css2?family=Codystar&display=swap”);

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 62.5%;
  font-family: -apple-system, BlinkMacSystemFont, “Segoe UI”, Roboto, Oxygen,
    Ubuntu, Cantarell, “Open Sans”, “Helvetica Neue”, sans-serif;
}

body {
  min-height: 100vh;
  color: var(–color-light);
  background-color: var(–color-darkest);
  padding: 3.2rem;
}

.app {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.main {
  width: 50rem;
}

.app-header {
  width: 66rem;
  margin-bottom: 4rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.error {
  text-align: center;
  font-size: 1.6rem;
  font-weight: 500;
  padding: 2rem;
  background-color: #495057;
  border-radius: 100px;
}

img {
  width: 14rem;
}

h1 {
  font-family: “Codystar”;
  font-size: 5.6rem;
}

h2 {
  font-size: 3.6rem;
  margin-bottom: 2rem;
}

h3 {
  font-size: 2.4rem;
  font-weight: 600;
  margin-bottom: 4rem;
}

h4 {
  font-size: 2.2rem;
  font-weight: 600;
  margin-bottom: 2.4rem;
}

.start {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.progress {
  margin-bottom: 4rem;
  display: grid;
  justify-content: space-between;
  gap: 1.2rem;
  grid-template-columns: auto auto;
  font-size: 1.8rem;
  color: var(–color-medium);
}

progress {
  -webkit-appearance: none;
  width: 100%;
  height: 12px;
  grid-column: 1 / -1;
}

::-webkit-progress-bar {
  background-color: var(–color-medium);
  border-radius: 100px;
}
::-webkit-progress-value {
  background-color: var(–color-theme);
  border-radius: 100px;
}

.btn {
  display: block;
  font-family: inherit;
  color: inherit;
  font-size: 2rem;
  border: 2px solid var(–color-dark);
  background-color: var(–color-dark);
  padding: 1.2rem 2.4rem;
  cursor: pointer;
  border-radius: 100px;
  transition: 0.3s;
}

.btn:not([disabled]):hover {
  background-color: var(–color-darkest);
}

.btn-option:not([disabled]):hover {
  transform: translateX(1.2rem);
}

.btn[disabled]:hover {
  cursor: not-allowed;
}

.btn-ui {
  float: right;
}

.options {
  display: flex;
  flex-direction: column;
  gap: 1.2rem;
  margin-bottom: 3.2rem;
}

.btn-option {
  width: 100%;
  text-align: left;
}

.btn-option.correct {
  background-color: var(–color-theme);
  border: 2px solid var(–color-theme);
  color: var(–color-light);
}
.btn-option.wrong {
  background-color: var(–color-accent);
  border: 2px solid var(–color-accent);
  color: var(–color-darkest);
}

.answer {
  transform: translateX(2rem);
}

.result {
  background-color: var(–color-theme);
  color: var(–color-light);
  border-radius: 100px;
  text-align: center;
  padding: 2rem 0;
  font-size: 2rem;
  font-weight: 500;
  margin-bottom: 1.6rem;
}

.result span {
  font-size: 2.2rem;
  margin-right: 4px;
}

.highscore {
  font-size: 1.8rem;
  text-align: center;
  margin-bottom: 4.8rem;
}

.loader-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-top: 4rem;
  gap: 1.6rem;

  color: var(–color-medium);
  font-size: 1.4rem;
}

.timer {
  float: left;
  font-size: 1.8rem;
  color: var(–color-medium);
  border: 2px solid var(–color-dark);
  padding: 1.35rem 2.8rem;
  border-radius: 100px;
}

/* CREDIT: https://dev.to/afif/i-made-100-css-loaders-for-your-next-project-4eje */
.loader {
  width: 50px;
  height: 24px;
  background: radial-gradient(circle closest-side, currentColor 90%, #0000) 0%
      50%,
    radial-gradient(circle closest-side, currentColor 90%, #0000) 50% 50%,
    radial-gradient(circle closest-side, currentColor 90%, #0000) 100% 50%;
  background-size: calc(100% / 3) 12px;
  background-repeat: no-repeat;
  animation: loader 1s infinite linear;
}

@keyframes loader {
  20% {
    background-position: 0% 0%, 50% 50%, 100% 50%;
  }
  40% {
    background-position: 0% 100%, 50% 0%, 100% 50%;
  }
  60% {
    background-position: 0% 50%, 50% 100%, 100% 0%;
  }
  80% {
    background-position: 0% 50%, 50% 50%, 100% 100%;
  }
}

/* ********** */
/* First counter example */
.counter {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  font-size: 2rem;
  font-weight: bold;
  margin: 6rem;
}

.counter * {
  font-size: inherit;
  padding: 0.8rem;
}

 

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, “Segoe UI”, Roboto,
    Oxygen, Ubuntu, Cantarell, “Open Sans”, “Helvetica Neue”, sans-serif;

 

  color: #222;
  line-height: 1.25;
  background: #fff;
  padding: 32px;
}

 

.fake-dark-mode {
  filter: invert(100%);
  transition: all 0.5s;
}

 

.btn-fake-dark-mode {
  position: fixed;
  top: 0;
  right: 0;
  padding: 16px;
  line-height: 1;
  font-size: 26px;
  background-color: #ffe8cc;
  border: none;
}

 

section {
  max-width: 1140px;
  margin: 0 auto;
}

 

header {
  margin-bottom: 32px;
  font-weight: bold;

 

  justify-content: space-between;
  display: flex;
}

 

h1 {
  font-size: 26px;
  display: flex;
  gap: 8px;
  align-items: center;
}

 

h1 span {
  font-size: 140%;
  line-height: 1;
}

 

h2 {
  text-transform: uppercase;
  margin-bottom: 24px;
  color: #333;
}

 

h3 {
  text-transform: capitalize;
  margin-bottom: 16px;
  color: #333;
}

 

header div {
  display: flex;
  gap: 32px;
  align-items: center;
}

 

header button {
  font-size: 14px;
}

 

form {
  padding: 24px;
  background-color: #fff4e6;
  display: flex;
  gap: 24px;
  margin-bottom: 40px;
}

 

main {
  margin-bottom: 40px;
}

 

aside {
  margin-bottom: 40px;
  opacity: 75%;
}

 

input,
textarea,
button {
  font-size: 16px;
  padding: 8px 12px;
  border: 1px solid #ffe8cc;
  font-family: inherit;
  color: inherit;
}

 

input {
  width: 12rem;
}

 

*::placeholder {
  color: #999;
}

 

*:focus {
  outline: 2px solid #ffa94d;
  border-radius: 2px;
}

 

textarea {
  flex: 1;
  height: 50px;
}

 

button {
  border: 1px solid #ffa94d;
  background-color: #ffa94d;
  font-weight: 700;
  padding: 9px 24px;
  cursor: pointer;
}

 

h3 {
  text-transform: capitalize;
  margin-bottom: 16px;
  color: #333;
}

 

main ul {
  list-style: none;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 1fr;
  gap: 32px;
}

 

main li {
  border: 1px solid #ffe8cc;
  padding: 16px 20px;
}

 

main li:hover {
  background-color: #fff4e6;
}

 

aside ul {
  font-size: 90%;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

 

aside li {
  border: 1px solid #ffe8cc;
  padding: 4px 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

 

h2 + button {
  margin-bottom: 24px;
}

 

aside li button {
  padding: 4px 8px;
  font-size: 14px;
}