Lifting State in React Setup
Setup
Open your Terminal application and navigate to your ~/code/ga/lectures directory:
cd ~/code/ga/lectures
Create a new Vite project for your React app:
npm create vite@latest
You’ll be prompted to choose a project name. Let’s name it lifting-state-in-react.
-
Select a framework. Use the arrow keys to choose the
Reactoption and hitEnter. -
Select a variant. Again, use the arrow keys to choose
JavaScriptand hitEnter.
Navigate to your new project directory and install the necessary dependencies:
cd lifting-state-in-react
npm i
Create a new directory to hold future components:
mkdir src/components
Then, open the project’s folder in your code editor:
code .
Configuring ESLint
Before we begin, we need to adjust the ESLint configuration. Add the indicated rules to the rules object in your eslint.config.js file:
rules: {
...js.configs.recommended.rules,
...react.configs.recommended.rules,
...react.configs['jsx-runtime'].rules,
...reactHooks.configs.recommended.rules,
'react/jsx-no-target-blank': 'off',
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true },
],
'react/prop-types': 'off', // add this line
'react/no-unescaped-entities': 'off', // add this line
},
The first addition prevents warnings if you don’t declare types for your props (which we’re not), and the second prevents warnings if you use contractions within JSX.
Clear App.jsx
Open the App.jsx file in the src directory and replace the contents of it with the following:
// src/App.jsx
const App = () => {
return (
<h1>Hello world!</h1>
);
};
export default App;