Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
jun68ykt
committed
Aug 19, 2019
0 parents
commit 601f340
Showing
11 changed files
with
10,250 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. | ||
|
||
# dependencies | ||
/node_modules | ||
/.pnp | ||
.pnp.js | ||
|
||
# testing | ||
/coverage | ||
|
||
# production | ||
/build | ||
|
||
# misc | ||
.DS_Store | ||
.env.local | ||
.env.development.local | ||
.env.test.local | ||
.env.production.local | ||
|
||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
/.idea | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# tl;dr | ||
|
||
This repo contains my answer codes of a React app for | ||
[the question No.206957 of teratail](https://teratail.com/questions/206957), which is a Japanese Programming Q&A site. | ||
|
||
# how to run | ||
|
||
- yarn install | ||
- yarn start |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{ | ||
"name": "q206957", | ||
"version": "0.1.0", | ||
"private": true, | ||
"dependencies": { | ||
"react": "^16.9.0", | ||
"react-dom": "^16.9.0", | ||
"react-redux": "^7.1.0", | ||
"react-scripts": "3.1.1", | ||
"redux": "^4.0.4" | ||
}, | ||
"scripts": { | ||
"start": "react-scripts start", | ||
"build": "react-scripts build", | ||
"test": "react-scripts test", | ||
"eject": "react-scripts eject" | ||
}, | ||
"eslintConfig": { | ||
"extends": "react-app" | ||
}, | ||
"browserslist": { | ||
"production": [ | ||
">0.2%", | ||
"not dead", | ||
"not op_mini all" | ||
], | ||
"development": [ | ||
"last 1 chrome version", | ||
"last 1 firefox version", | ||
"last 1 safari version" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<!DOCTYPE html> | ||
<html lang="ja"> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<title>Q206957</title> | ||
</head> | ||
<body> | ||
<div id="root"></div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
export const INCREMENT = 'INCREMENT' | ||
export const DECREMENT = 'DECREMENT' | ||
|
||
export const onIncrement = () => { | ||
return { | ||
type: INCREMENT | ||
} | ||
} | ||
|
||
export const onDecrement = () => { | ||
return { | ||
type: DECREMENT | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import React from 'react'; | ||
|
||
const Counter = ({ count, increment, decrement }) => { | ||
return ( | ||
<div> | ||
<span>{count}</span> | ||
<button onClick={increment}>+1</button> | ||
<button onClick={decrement}>-1</button> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Counter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import Counter from '../components/Counter' | ||
import { onIncrement, onDecrement } from '../actions' | ||
import { connect } from 'react-redux'; | ||
|
||
const mapStateToProps = (state) => ({ | ||
count: state.counterReducer.count | ||
}) | ||
|
||
const mapDispatchToProps = (dispatch) => ({ | ||
increment: () => dispatch(onIncrement()), | ||
decrement: () => dispatch(onDecrement()) | ||
}) | ||
|
||
export default connect(mapStateToProps, mapDispatchToProps)(Counter) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import React from 'react'; | ||
import { render } from 'react-dom'; | ||
import { Provider } from 'react-redux'; | ||
import { createStore } from 'redux'; | ||
import CounterContainer from './containers/Counter'; | ||
import reducer from './reducers' | ||
|
||
const store = createStore(reducer); | ||
|
||
render( | ||
<Provider store={store}> | ||
<CounterContainer /> | ||
{/* ここにもう一つカウンターを設置したい */} | ||
</Provider>, | ||
document.getElementById('root') | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { INCREMENT, DECREMENT } from '../actions' | ||
|
||
export const counterReducer = (state = {count: 0}, action) => { | ||
switch (action.type) { | ||
case INCREMENT: | ||
return { | ||
...state, | ||
count: state.count + 1 | ||
} | ||
case DECREMENT: | ||
return { | ||
...state, | ||
count: state.count - 1 | ||
} | ||
default: | ||
return state | ||
} | ||
} | ||
export default counterReducer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { combineReducers } from 'redux' | ||
import { counterReducer } from './counter' | ||
|
||
const reducer = combineReducers({ | ||
counterReducer, | ||
}) | ||
|
||
export default reducer |
Oops, something went wrong.