Skip to content

Commit 4961c63

Browse files
authored
Adding-Props-To-Counter-PropTypes-And-Defaults
1 parent 70c21af commit 4961c63

File tree

17 files changed

+16880
-0
lines changed

17 files changed

+16880
-0
lines changed

Adding-Props-To-Counter-PropTypes-And-Defaults/frontend/todo-app/package-lock.json

Lines changed: 16458 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"name": "todo-app",
3+
"version": "0.1.0",
4+
"private": true,
5+
"dependencies": {
6+
"react": "^16.8.4",
7+
"react-dom": "^16.8.4",
8+
"react-scripts": "2.1.8"
9+
},
10+
"scripts": {
11+
"start": "react-scripts start",
12+
"build": "react-scripts build",
13+
"test": "react-scripts test",
14+
"eject": "react-scripts eject"
15+
},
16+
"eslintConfig": {
17+
"extends": "react-app"
18+
},
19+
"browserslist": [
20+
">0.2%",
21+
"not dead",
22+
"not ie <= 11",
23+
"not op_mini all"
24+
]
25+
}
Binary file not shown.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8" />
5+
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico" />
6+
<meta
7+
name="viewport"
8+
content="width=device-width, initial-scale=1, shrink-to-fit=no"
9+
/>
10+
<meta name="theme-color" content="#000000" />
11+
<!--
12+
manifest.json provides metadata used when your web app is installed on a
13+
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
14+
-->
15+
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
16+
<!--
17+
Notice the use of %PUBLIC_URL% in the tags above.
18+
It will be replaced with the URL of the `public` folder during the build.
19+
Only files inside the `public` folder can be referenced from the HTML.
20+
21+
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
22+
work correctly both with client-side routing and a non-root public URL.
23+
Learn how to configure a non-root public URL by running `npm run build`.
24+
-->
25+
<title>My Todo Application</title>
26+
</head>
27+
<body>
28+
<noscript>You need to enable JavaScript to run this app.</noscript>
29+
<div id="root"></div>
30+
<!--
31+
This HTML file is a template.
32+
If you open it directly in the browser, you will see an empty page.
33+
34+
You can add webfonts, meta tags, or analytics to this file.
35+
The build step will place the bundled scripts into the <body> tag.
36+
37+
To begin the development, run `npm start` or `yarn start`.
38+
To create a production bundle, use `npm run build` or `yarn build`.
39+
-->
40+
</body>
41+
</html>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"short_name": "React App",
3+
"name": "Create React App Sample",
4+
"icons": [
5+
{
6+
"src": "favicon.ico",
7+
"sizes": "64x64 32x32 24x24 16x16",
8+
"type": "image/x-icon"
9+
}
10+
],
11+
"start_url": ".",
12+
"display": "standalone",
13+
"theme_color": "#000000",
14+
"background_color": "#ffffff"
15+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
.App {
2+
text-align: center;
3+
}
4+
5+
.App-logo {
6+
animation: App-logo-spin infinite 20s linear;
7+
height: 40vmin;
8+
pointer-events: none;
9+
}
10+
11+
.App-header {
12+
background-color: #282c34;
13+
min-height: 100vh;
14+
display: flex;
15+
flex-direction: column;
16+
align-items: center;
17+
justify-content: center;
18+
font-size: calc(10px + 2vmin);
19+
color: white;
20+
}
21+
22+
.App-link {
23+
color: #61dafb;
24+
}
25+
26+
@keyframes App-logo-spin {
27+
from {
28+
transform: rotate(0deg);
29+
}
30+
to {
31+
transform: rotate(360deg);
32+
}
33+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import React, { Component } from 'react';
2+
import FirstComponent from './components/learning-examples/FirstComponent'
3+
import SecondComponent from './components/learning-examples/SecondComponent'
4+
import ThirdComponent from './components/learning-examples/ThirdComponent'
5+
import Counter from './components/counter/Counter'
6+
import './App.css';
7+
8+
class App extends Component {
9+
render() {
10+
return (
11+
<div className="App">
12+
<Counter by={1}/>
13+
<Counter by={5}/>
14+
<Counter by={10}/>
15+
</div>
16+
);
17+
}
18+
}
19+
20+
class LearningComponents extends Component {
21+
render() {
22+
return (
23+
<div className="LearningComponents">
24+
My Hello World
25+
<FirstComponent></FirstComponent>
26+
<SecondComponent></SecondComponent>
27+
<ThirdComponent></ThirdComponent>
28+
</div>
29+
);
30+
}
31+
}
32+
33+
export default App;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import React from 'react';
2+
import ReactDOM from 'react-dom';
3+
import App from './App';
4+
5+
it('renders without crashing', () => {
6+
const div = document.createElement('div');
7+
ReactDOM.render(<App />, div);
8+
ReactDOM.unmountComponentAtNode(div);
9+
});
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
button {
2+
background-color: green;
3+
font-size : 16px;
4+
padding : 15px 30px;
5+
color : white;
6+
width : 100px;
7+
}
8+
9+
.count {
10+
font-size : 50px;
11+
padding : 15px 30px;
12+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import React, {Component} from 'react'
2+
import PropTypes from 'prop-types'
3+
import './Counter.css'
4+
5+
class Counter extends Component {
6+
//Define the initial state in a constructor
7+
//state => counter 0
8+
constructor() {
9+
super(); //Error 1
10+
11+
this.state = {
12+
counter : 0
13+
}
14+
15+
this.increment = this.increment.bind(this);
16+
}
17+
18+
render() {
19+
//render = () => {
20+
//const style = {fontSize : "50px", padding : "15px 30px"};
21+
return (
22+
<div className="counter">
23+
<button onClick={this.increment} >+{this.props.by}</button>
24+
<span className="count"
25+
>{this.state.counter}</span>
26+
</div>
27+
)
28+
}
29+
30+
increment() { //Update state - counter++
31+
//console.log('increment');
32+
//this.state.counter++; //Bad Practice
33+
this.setState({
34+
counter: this.state.counter + this.props.by
35+
});
36+
}
37+
38+
}
39+
40+
Counter.defaultProps = {
41+
by : 1
42+
}
43+
44+
Counter.propTypes = {
45+
by : PropTypes.number
46+
}
47+
48+
export default Counter

0 commit comments

Comments
 (0)