Skip to content

Commit

Permalink
Squashed: redux with doc
Browse files Browse the repository at this point in the history
  • Loading branch information
Rauqoz committed Aug 18, 2022
1 parent 69ce29d commit 774f483
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 63 deletions.
55 changes: 11 additions & 44 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
"@testing-library/jest-dom": "^5.16.4",
"@testing-library/react": "^13.1.1",
"@testing-library/user-event": "^13.5.0",
"axios": "^0.27.2",
"react": "^18.0.0",
"react-dom": "^18.0.0",
"react-redux": "^8.0.1",
"react-router-dom": "^6.3.0",
"react-scripts": "5.0.1",
"redaxios": "^0.5.0",
"redux": "^4.2.0",
"redux-thunk": "^2.4.1",
"styled-components": "^5.3.5",
Expand Down
4 changes: 2 additions & 2 deletions frontend/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="Web site created using create-react-app"
content="Rauqoz Template Full Stack MERN"
/>
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<!--
Expand All @@ -24,7 +24,7 @@
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>React Template</title>
<title>Rauqoz Template</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
Expand Down
4 changes: 2 additions & 2 deletions frontend/public/manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"short_name": "React App",
"name": "Create React App Sample",
"short_name": "Rauqoz Template",
"name": "Rauqoz Template Full Stack MERN",
"icons": [
{
"src": "favicon.ico",
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import RoutesPath from './Routes/Routes';
/*
Check the folder "src/Middlewares/SocketIO/SocketIO"
*/
// import './Middlewares/SocketIO/SocketIO';
// import './Middlewares/SocketIO/socketIO';

function App() {
return <RoutesPath />;
Expand Down
12 changes: 3 additions & 9 deletions frontend/src/Middlewares/Redux/Actions/Template.actions.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import axios from 'axios';
import redaxios from 'redaxios';
export const UPDATE_POKEMON = 'UPDATE_POKEMON';
export const UPDATE_DATA_POKEMON = 'UPDATE_DATA_POKEMON';
export const RESET = 'RESET';
Expand Down Expand Up @@ -28,16 +28,10 @@ export const reset_ = () => {
export const search_pokemon_ = (poke) => {
return async (dispatch) => {
try {
var config = {
method: 'get',
url: `https://pokeapi.co/api/v2/pokemon/${poke}`,
headers: {}
};

const { data } = await axios(config);
const { data } = await redaxios.get(`https://pokeapi.co/api/v2/pokemon/${poke}`);
dispatch(update_data_pokemon_(data));
} catch (error) {
dispatch(update_data_pokemon_(`Error on Pokemon ${poke}`));
dispatch(update_data_pokemon_(`Error on Pokemon ${poke}!`));
}
};
};
43 changes: 43 additions & 0 deletions frontend/src/Middlewares/Redux/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,46 @@

## Installation and Use

Redux is implemented in this template, it is divided as follows:

>If you want to remove the use of redux, you must remove the following lines of code
In index.js
```javascript
// Example start --- you can remove from this line
import { Provider } from 'react-redux';
import store from './Middlewares/Redux/store';
// Example end --- to this line if you dont need the template

{/* Store for Redux */}
<Provider store={store}>
*Here your App*
</Provider>
{/* Delete the provider if you dont need redux */}
```

## Folder Actions

In this folder you can find the use of redaxios (already implemented) the states and an example of data handling and asynchronous requests

## Folder Reducers

In this folder you will find the reducers related to saving data in addition to the initial state

>For each reducer, 1 file is recommended
## File Store.js

In this file is "redux-thunk" implemented to be able to make asynchronous requests with "redaxios"

There is also the "createStore" method that generates the redux store by combining the necessary amount of reducers

```javascript
const all_reducers = combineReducers({ Template_reducer_ });

const store = createStore(all_reducers, applyMiddleware(thunk));
```

>If you need see the official doc for redux:
[Documentation](https://es.redux.js.org/docs/basico/)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RESET, UPDATE_DATA_POKEMON, UPDATE_POKEMON } from '../Actions/Template.actions';
import { RESET, UPDATE_DATA_POKEMON, UPDATE_POKEMON } from '../Actions/template.actions';

const InitialState = {
pokemon: '',
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/Middlewares/Redux/store.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { applyMiddleware, combineReducers, createStore } from 'redux';
import { applyMiddleware, combineReducers, legacy_createStore as createStore } from 'redux';
import thunk from 'redux-thunk';
// Example start --- you can remove from this line
import Template_reducer_ from './Reducers/Tempate.reducers';
const all_reducers = combineReducers({ Template_reducer_ });
import Template_reducer_ from './Reducers/tempate.reducers';
// Example end --- to this line if you dont need the template
const all_reducers = combineReducers({ Template_reducer_ });

const store = createStore(all_reducers, applyMiddleware(thunk));

Expand Down
3 changes: 3 additions & 0 deletions frontend/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ import React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import App from './App';
// Example start --- you can remove from this line
import { Provider } from 'react-redux';
import store from './Middlewares/Redux/store';
// Example end --- to this line if you dont need the template

const root = ReactDOM.createRoot(document.getElementById('root'));

Expand All @@ -13,5 +15,6 @@ root.render(
<Provider store={store}>
<App />
</Provider>
{/* Delete the provider if you dont need redux */}
</React.StrictMode>
);

0 comments on commit 774f483

Please sign in to comment.