Next, build the components from the top down starting with Navigation. First, open the component file in a text editor:

nano src/components/Navigation/Navigation.js
Open the file in your text editor:

nano src/components/SaladItem/SaladItem.js
state-context-tutorial/src/components/SaladMaker/SaladMaker.js

import React from 'react';
import { createUseStyles } from 'react-jss';

const useStyles = createUseStyles({
  wrapper: {
    textAlign: 'center',
  }
});

export default function SaladMaker() {
  const classes = useStyles();
  return(
    <>
      <h1 className={classes.wrapper}>
        <span role="img" aria-label="salad">🥗 </span>
          Build Your Custom Salad!
          <span role="img" aria-label="salad"> 🥗</span>
      </h1>
    </>
  )
}
state-context-tutorial/src/components/SaladSummary/SaladSummary.jss

import React from 'react';
import { createUseStyles } from 'react-jss';

const useStyles = createUseStyles({
  list: {
    display: 'flex',
    flexDirection: 'column',
    flexWrap: 'wrap',
    maxHeight: 50,
    '& li': {
      width: 100
    }
  },
  wrapper: {
    borderTop: 'black solid 1px',
    display: 'flex',
    padding: 25,
  }
});

export default function SaladSummary() {
  const classes = useStyles();
  return(
    <div className={classes.wrapper}>
      <h2>Your Salad</h2>
      <ul className={classes.list}>
        <li>Apple</li>
        <li>Avocado</li>
        <li>Carrots</li>
      </ul>
    </div>
  )
}
state-context-tutorial/src/components/Navigation/Navigation.js

import React from 'react';
import { createUseStyles } from 'react-jss';

const useStyles = createUseStyles({
  wrapper: {
    borderBottom: 'black solid 1px',
    padding: [15, 10],
    textAlign: 'right',
  }
});

export default function Navigation() {
  const classes = useStyles();
  return(
    <div className={classes.wrapper}>
      Welcome, Kwame
    </div>
  )
}
state-context-tutorial/src/components/SaladItem/SaladItem.js

import React from 'react';
import PropTypes from 'prop-types';
import { createUseStyles } from 'react-jss';

const useStyles = createUseStyles({
  add: {
    background: 'none',
    border: 'none',
    cursor: 'pointer',
  },
  favorite: {
    fontSize: 20,
    position: 'absolute',
    top: 10,
    right: 10,
  },
  image: {
    fontSize: 80
  },
  wrapper: {
    border: 'lightgrey solid 1px',
    margin: 20,
    padding: 25,
    position: 'relative',
    textAlign: 'center',
    textTransform: 'capitalize',
    width: 200,
  }
});

export default function SaladItem({ image, name }) {
  const classes = useStyles();
  const favorite = true;
  return(
    <div className={classes.wrapper}>
        <h3>
          {name}
        </h3>
        <span className={classes.favorite} aria-label={favorite ? 'Favorite' : 'Not Favorite'}>
          {favorite ? '😋' : ''}
        </span>
        <button className={classes.add}>
          <span className={classes.image} role="img" aria-label={name}>{image}</span>
        </button>
    </div>
  )
}

SaladItem.propTypes = {
  image: PropTypes.string.isRequired,
  name: PropTypes.string.isRequired,
}
state-context-tutorial/src/components/SaladBuilder/SaladBuilder.js

import React from 'react';
import SaladItem from '../SaladItem/SaladItem';

import { createUseStyles } from 'react-jss';

const useStyles = createUseStyles({
  wrapper: {
    display: 'flex',
    flexWrap: 'wrap',
    padding: [10, 50],
    justifyContent: 'center',
  }
});

const ingredients = [
  {
    image: '🍎',
    name: 'apple',
  },
  {
    image: '🥑',
    name: 'avocado',
  },
  {
    image: '🥦',
    name: 'broccoli',
  },
  {
    image: '🥕',
    name: 'carrot',
  },
  {
    image: '🍷',
    name: 'red wine dressing',
  },
  {
    image: '🍚',
    name: 'seasoned rice',
  },
];

export default function SaladBuilder() {
  const classes = useStyles();
  return(
    <div className={classes.wrapper}>
      {
        ingredients.map(ingredient => (
          <SaladItem
            key={ingredient.name}
            image={ingredient.image}
            name={ingredient.name}
          />
        ))
      }
    </div>
  )
}
Now that you have an idea of the components you’ll need, make a directory for each one:

mkdir src/components/Navigation
mkdir src/components/SaladMaker
mkdir src/components/SaladItem
mkdir src/components/SaladBuilder
mkdir src/components/SaladSummary
state-context-tutorial/src/components/App/App.js

import React from 'react';
import Navigation from '../Navigation/Navigation';

function App() {
  return (
    <>
      <Navigation />
    </>
  );
}

export default App;
npm will install the component, and when it completes you’ll see a message like this:

Output+ react-jss@10.3.0
added 27 packages from 10 contributors, removed 10 packages andaudited 1973 packages in 15.507s

Recommend

How To Share State Across React Components with Context Step 1 — Building the Basis for Your Application

Información sobre GOPATH ¿Qué son los paquetes?

Información sobre GOPATH Anatomía del espacio de trabajo de Go

Python 3をインストールしUbuntu 20.04サーバーにプログラミング環境を設定する方法 ステップ3 —「Hello、World」プログラムの作成

Python 3をインストールしUbuntu 20.04サーバーにプログラミング環境を設定する方法 ステップ2 —仮想環境のセットアップ

Python 3をインストールしUbuntu 20.04サーバーにプログラミング環境を設定する方法 ステップ1 — Python 3のセットアップ

Información sobre init en Go Usar init() para efectos secundarios

Información sobre init en Go Varias instancias de init()

Información sobre init en Go Inicializar paquetes en la importación

Información sobre init en Go Declarar init()

Información sobre init en Go Requisitos previos

Cara Menginstal tumpukan Linux, Apache, MySQL, PHP (LAMP) pada Ubuntu 20.04 Langkah 6 — Menguji Koneksi Basis Data dari PHP (Opsional)

Cara Menginstal tumpukan Linux, Apache, MySQL, PHP (LAMP) pada Ubuntu 20.04 Langkah 5 — Menguji Pemrosesan PHP pada Server Web

Cara Menginstal tumpukan Linux, Apache, MySQL, PHP (LAMP) pada Ubuntu 20.04 Langkah 4 — Menciptakan Hos Virtual untuk Situs Web Anda Catatan Tentang DirectoryIndex pada Apache

Cara Menginstal tumpukan Linux, Apache, MySQL, PHP (LAMP) pada Ubuntu 20.04 Langkah 4 — Menciptakan Hos Virtual untuk Situs Web Anda

Cara Menginstal tumpukan Linux, Apache, MySQL, PHP (LAMP) pada Ubuntu 20.04 Langkah 3 — Menginstal PHP

Cara Menginstal tumpukan Linux, Apache, MySQL, PHP (LAMP) pada Ubuntu 20.04 Langkah 2 — Menginstal MySQL