Skip to content

Commit db4a119

Browse files
committed
Criando o projeto
1 parent 9b12560 commit db4a119

File tree

3 files changed

+16
-13
lines changed

3 files changed

+16
-13
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "templete-redux",
2+
"name": "notes-app",
33
"version": "0.1.0",
44
"private": true,
55
"dependencies": {
Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,33 @@
1-
import React from 'react';
1+
import React, { useState } from 'react';
22
import { useSelector, useDispatch } from 'react-redux';
33
import { Types } from '../../store/reducer/example-reducer';
44

55
export default function ComponentList() {
66

77
const qty = 20
8+
const [text, setText] = useState('')
89

910
const list = useSelector(
10-
state => state.exampleReducer.data.slice(0, qty)
11+
state => state.exampleReducer.data.slice(0, qty)
1112
, [qty]);
1213
const dispatch = useDispatch();
1314

14-
function add(){
15-
dispatch({ type: Types.ADD, title: 'GrafQL'})
15+
function add() {
16+
dispatch({ type: Types.ADD, title: text })
1617
}
1718

1819
return (
1920
<>
21+
<textarea
22+
cols={100}
23+
rows={10}
24+
value={text}
25+
onChange={e => setText(e.target.value)}
26+
/>
27+
<button type="button" onClick={add}>ADD</button>
2028
<ul>
21-
{list.map( item => <li key={item}>{item}</li>)}
29+
{list.map(item => <li key={item}>{item}</li>)}
2230
</ul>
23-
<button type="button" onClick={add}>ADD</button>
2431
</>
2532
);
2633
}

src/store/reducer/example-reducer.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,11 @@ export const { Types, Creators } = createActions({
99
})
1010

1111
const INITIAL_STATE = {
12-
data: [
13-
'React Native',
14-
'ReactJS',
15-
'NodeJS'
16-
]
12+
data: []
1713
}
1814

1915
const add = (state = INITIAL_STATE, action) => {
20-
return { ...state, data: [ ...state.data, action.title ]}
16+
return { ...state, data: [...state.data, action.title] }
2117
}
2218

2319
/**

0 commit comments

Comments
 (0)