Setting Up the Application
We will create a new project using the react-redux
template. Open the console and cd
into an appropriate location, then create a new project using the command: npx create-react-app post-app --template redux
.
Now that the project is set up, we need to remove the default counter application and delete everything in the src
folder.
We will create a new index.js
file containing the following base code:
import React from 'react';
import { createRoot } from 'react-dom/client';
import { Provider } from 'react-redux';
import { store } from './app/store';
const container = document.getElementById('root');
const root = createRoot(container);
function Main(props) {
return (<h1>Hello World</h1>);
}
root.render(
<React.StrictMode>
<Provider store={store}>
<Main />
</Provider>
</React.StrictMode>
);
Since we are also importing a store, we will create a new store.js
in a new app folder:
import { configureStore } from '@reduxjs/toolkit';
export const store = configureStore({
reducer: {},
});
Now we can run the app to see a 'Hello World'
screen:
However, this is only a setup, there's more to do!
Дякуємо за ваш відгук!
Запитати АІ
Запитати АІ
Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат
Awesome!
Completion rate improved to 3.45
Setting Up the Application
Свайпніть щоб показати меню
We will create a new project using the react-redux
template. Open the console and cd
into an appropriate location, then create a new project using the command: npx create-react-app post-app --template redux
.
Now that the project is set up, we need to remove the default counter application and delete everything in the src
folder.
We will create a new index.js
file containing the following base code:
import React from 'react';
import { createRoot } from 'react-dom/client';
import { Provider } from 'react-redux';
import { store } from './app/store';
const container = document.getElementById('root');
const root = createRoot(container);
function Main(props) {
return (<h1>Hello World</h1>);
}
root.render(
<React.StrictMode>
<Provider store={store}>
<Main />
</Provider>
</React.StrictMode>
);
Since we are also importing a store, we will create a new store.js
in a new app folder:
import { configureStore } from '@reduxjs/toolkit';
export const store = configureStore({
reducer: {},
});
Now we can run the app to see a 'Hello World'
screen:
However, this is only a setup, there's more to do!
Дякуємо за ваш відгук!