Skip to content

Commit a203d77

Browse files
author
Catharina Mesquita
committed
Refatorando nomes dos reduces para melhor atender
1 parent 84ac96e commit a203d77

File tree

4 files changed

+24
-4
lines changed

4 files changed

+24
-4
lines changed

src/components/ComponentList/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import React from 'react';
22
import { useSelector, useDispatch } from 'react-redux';
3-
import { Types } from '../../store/reducer';
3+
import { Types } from '../../store/reducer/example-reducer';
44

55
export default function ComponentList() {
66

77
const qty = 20
88

99
const list = useSelector(
10-
state => state.data.slice(0, qty)
10+
state => state.exampleReducer.data.slice(0, qty)
1111
, [qty]);
1212
const dispatch = useDispatch();
1313

src/store/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { createStore } from 'redux'
22

3-
import reducer from './reducer'
3+
import rootReducer from './reducer'
44

5-
const store = createStore(reducer)
5+
const store = createStore(rootReducer)
66

77
export default store;

src/store/reducer.js renamed to src/store/reducer/example-reducer.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import { createActions, createReducer } from 'reduxsauce';
22

3+
/**
4+
* Criando os Types e Creators
5+
* Ex.: Type.ADD e add = { type: Type.ADD, params }
6+
*/
37
export const { Types, Creators } = createActions({
48
add: ["title"]
59
})
@@ -16,6 +20,15 @@ const add = (state = INITIAL_STATE, action) => {
1620
return { ...state, data: [ ...state.data, action.title ]}
1721
}
1822

23+
/**
24+
* Criando os reducers
25+
* Ex.: [Types.ADD]: add == switch actions.type
26+
* case Type.ADD
27+
* return add(state, action)
28+
* default
29+
* return state
30+
*/
31+
1932
export default createReducer(INITIAL_STATE, {
2033
[Types.ADD]: add,
2134
})

src/store/reducer/index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { combineReducers } from 'redux';
2+
3+
import exampleReducer from './example-reducer'
4+
5+
export default combineReducers({
6+
exampleReducer,
7+
})

0 commit comments

Comments
 (0)