Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jun68ykt committed Aug 19, 2019
0 parents commit 601f340
Show file tree
Hide file tree
Showing 11 changed files with 10,250 additions and 0 deletions.
26 changes: 26 additions & 0 deletions .gitignore
@@ -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

9 changes: 9 additions & 0 deletions README.md
@@ -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
33 changes: 33 additions & 0 deletions package.json
@@ -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"
]
}
}
10 changes: 10 additions & 0 deletions public/index.html
@@ -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>
14 changes: 14 additions & 0 deletions src/actions/index.js
@@ -0,0 +1,14 @@
export const INCREMENT = 'INCREMENT'
export const DECREMENT = 'DECREMENT'

export const onIncrement = () => {
return {
type: INCREMENT
}
}

export const onDecrement = () => {
return {
type: DECREMENT
}
}
13 changes: 13 additions & 0 deletions src/components/Counter.js
@@ -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
14 changes: 14 additions & 0 deletions src/containers/Counter.js
@@ -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)
16 changes: 16 additions & 0 deletions src/index.js
@@ -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')
);
19 changes: 19 additions & 0 deletions src/reducers/counter.js
@@ -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
8 changes: 8 additions & 0 deletions src/reducers/index.js
@@ -0,0 +1,8 @@
import { combineReducers } from 'redux'
import { counterReducer } from './counter'

const reducer = combineReducers({
counterReducer,
})

export default reducer

0 comments on commit 601f340

Please sign in to comment.