@@ -389,9 +389,7 @@ Agregamos una nueva nota al estado con el método _state.push(action.data)_ que
389389``` js
390390const noteReducer = (state = [], action ) => {
391391 if (action .type === ' NEW_NOTE' ) {
392- // highlight-start
393392 return state .concat (action .data )
394- // highlight-stop
395393 }
396394
397395 return state
@@ -576,9 +574,7 @@ Agregar una nueva nota crea el estado que devuelve con la función de Arrays _co
576574const noteReducer = (state = [], action ) => {
577575 switch (action .type ) {
578576 case ' NEW_NOTE' :
579- // highlight-start
580577 return [... state, action .data ]
581- // highlight-stop
582578 case ' TOGGLE_IMPORTANCE' :
583579 // ...
584580 default :
@@ -764,50 +760,42 @@ Tu aplicación puede tener una apariencia modesta, nada más se necesitan 3 boto
764760Agreguemos la funcionalidad para agregar nuevas notas y cambiar su importancia:
765761
766762``` js
767- // highlight-start
768763const generateId = () =>
769764 Number ((Math .random () * 1000000 ).toFixed (0 ))
770- // highlight-stop
771765
772766const App = () => {
773- // highlight-start
774767 const addNote = (event ) => {
775768 event .preventDefault ()
776769 const content = event .target .note .value
777770 event .target .note .value = ' '
778771 store .dispatch ({
779772 type: ' NEW_NOTE' ,
780- payload : {
773+ data : {
781774 content,
782775 important: false ,
783776 id: generateId ()
784777 }
785778 })
786779 }
787- // highlight-end
788780
789- // highlight-start
790781 const toggleImportance = (id ) => {
791782 store .dispatch ({
792783 type: ' TOGGLE_IMPORTANCE' ,
793- payload : { id }
784+ data : { id }
794785 })
795786 }
796- // highlight-end
797787
798788 return (
799789 < div>
800- // highlight-start
801790 < form onSubmit= {addNote}>
802791 < input name= " note" / >
803792 < button type= " submit" > add< / button>
804793 < / form>
805- // highlight-end
806794 < ul>
807795 {store .getState ().map (note =>
808796 < li
809797 key= {note .id }
810- onClick= {() => toggleImportance (note .id )} // highlight-line
798+ onClick= {() => toggleImportance (note .id )}
811799 >
812800 {note .content } < strong> {note .important ? ' important' : ' ' }< / strong>
813801 < / li>
@@ -818,6 +806,7 @@ const App = () => {
818806}
819807```
820808
809+
821810La implementación de ambas funcionalidades es sencilla. Cabe señalar que <i >no hemos</i > vinculado el estado de los campos del formulario al estado del componente <i >App</i > como lo hicimos anteriormente. React llama a este tipo de formulario [ no controlado] ( https://reactjs.org/docs/uncontrolled-components.html ) .
822811
823812
0 commit comments