Skip to content

Commit db67a39

Browse files
author
Catharina Mesquita
committed
v1 - template redux
1 parent 345d32a commit db67a39

File tree

9 files changed

+54
-205
lines changed

9 files changed

+54
-205
lines changed

src/App.css

Lines changed: 0 additions & 22 deletions
This file was deleted.

src/App.js

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,14 @@
11
import React from 'react';
2-
import logo from './logo.svg';
3-
import './App.css';
2+
import { Provider } from 'react-redux';
3+
4+
import store from './store'
5+
import ComponentList from './components/ComponentList';
46

57
function App() {
68
return (
7-
<div className="App">
8-
<header className="App-header">
9-
<img src={logo} className="App-logo" alt="logo" />
10-
<p>
11-
Edit <code>src/App.js</code> and save to reload.
12-
</p>
13-
<a
14-
className="App-link"
15-
href="https://reactjs.org"
16-
target="_blank"
17-
rel="noopener noreferrer"
18-
>
19-
Learn React
20-
</a>
21-
</header>
22-
</div>
9+
<Provider store={store}>
10+
<ComponentList />
11+
</Provider>
2312
);
2413
}
2514

src/App.test.js

Lines changed: 0 additions & 9 deletions
This file was deleted.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import React from 'react';
2+
import { useSelector, useDispatch } from 'react-redux';
3+
4+
export default function ComponentList() {
5+
6+
const qty = 20
7+
8+
const list = useSelector(
9+
state => state.data.slice(0, qty)
10+
, [qty]);
11+
const dispatch = useDispatch();
12+
13+
function add(){
14+
dispatch({ type: 'ADD_REDUCER', title: 'GrafQL'})
15+
}
16+
17+
return (
18+
<>
19+
<ul>
20+
{list.map( item => <li key={item}>{item}</li>)}
21+
</ul>
22+
<button type="button" onClick={add}>ADD</button>
23+
</>
24+
);
25+
}

src/index.css

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/index.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
11
import React from 'react';
22
import ReactDOM from 'react-dom';
3-
import './index.css';
43
import App from './App';
5-
import * as serviceWorker from './serviceWorker';
64

75
ReactDOM.render(<App />, document.getElementById('root'));
8-
9-
// If you want your app to work offline and load faster, you can change
10-
// unregister() to register() below. Note this comes with some pitfalls.
11-
// Learn more about service workers: https://bit.ly/CRA-PWA
12-
serviceWorker.unregister();

src/logo.svg

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/serviceWorker.js

Lines changed: 0 additions & 135 deletions
This file was deleted.

src/store/index.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { createStore } from 'redux'
2+
3+
const INITIAL_STATE = {
4+
data: [
5+
'React Native',
6+
'ReactJS',
7+
'NodeJS'
8+
]
9+
}
10+
11+
function reducer(state = INITIAL_STATE, action){
12+
switch (action.type) {
13+
case 'ADD_REDUCER':
14+
return { ...state, data: [ ...state.data, action.title ]}
15+
default:
16+
return state;
17+
}
18+
}
19+
20+
const store = createStore(reducer)
21+
22+
export default store;

0 commit comments

Comments
 (0)