Skip to content
This repository has been archived by the owner on Sep 15, 2023. It is now read-only.

Commit

Permalink
기초: reducer와 action을 이용해서 새로운 state 값 만들기
Browse files Browse the repository at this point in the history
  • Loading branch information
mjun0328 committed Sep 14, 2023
1 parent 171fcf9 commit f2e8c17
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions with-redux.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,16 @@
<div id="red"></div>
<script>
function reducer(state, action) {
console.log(state, action);
if (state === undefined) {
return { color: "yellow" };
}

let newState;
if (action.type === "CHANGE_COLOR") {
newState = Object.assign({}, state, { color: "red" });
}
return newState;
}
const store = Redux.createStore(reducer);

Expand All @@ -28,9 +35,7 @@
<div class="container" id="component_red" style="background-color: ${state.color}">
<h1>Red</h1>
<input type="button" value="fire" onclick="
document.querySelector('#component_red').style.backgroundColor = 'red';
document.querySelector('#component_green').style.backgroundColor = 'red';
document.querySelector('#component_blue').style.backgroundColor = 'red';
store.dispatch({type: 'CHANGE_COLOR', color: 'red'})
">
</div>
`;
Expand Down

0 comments on commit f2e8c17

Please sign in to comment.