Skip to content

Commit 749fc8d

Browse files
committed
🎉
0 parents  commit 749fc8d

29 files changed

+11313
-0
lines changed

.gitignore

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Dependencies
2+
/node_modules
3+
4+
# Production
5+
/build
6+
7+
# Generated files
8+
.docusaurus
9+
.cache-loader
10+
11+
# Misc
12+
.DS_Store
13+
.env.local
14+
.env.development.local
15+
.env.test.local
16+
.env.production.local
17+
18+
npm-debug.log*
19+
yarn-debug.log*
20+
yarn-error.log*

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Website
2+
3+
This website is built using [Docusaurus 2](https://v2.docusaurus.io/), a modern static website generator.
4+
5+
## Installation
6+
7+
```console
8+
yarn install
9+
```
10+
11+
## Local Development
12+
13+
```console
14+
yarn start
15+
```
16+
17+
This command starts a local development server and open up a browser window. Most changes are reflected live without having to restart the server.
18+
19+
## Build
20+
21+
```console
22+
yarn build
23+
```
24+
25+
This command generates static content into the `build` directory and can be served using any static contents hosting service.

babel.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
presets: [require.resolve('@docusaurus/core/lib/babel/preset')],
3+
};

blog/2019-05-28-hola.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
slug: hola
3+
title: Hola
4+
author: Gao Wei
5+
author_title: Docusaurus Core Team
6+
author_url: https://github.com/wgao19
7+
author_image_url: https://avatars1.githubusercontent.com/u/2055384?v=4
8+
tags: [hola, docusaurus]
9+
---
10+
11+
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque elementum dignissim ultricies. Fusce rhoncus ipsum tempor eros aliquam consequat. Lorem ipsum dolor sit amet

blog/2019-05-29-hello-world.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
slug: hello-world
3+
title: Hello
4+
author: Endilie Yacop Sucipto
5+
author_title: Maintainer of Docusaurus
6+
author_url: https://github.com/endiliey
7+
author_image_url: https://avatars1.githubusercontent.com/u/17883920?s=460&v=4
8+
tags: [hello, docusaurus]
9+
---
10+
11+
Welcome to this blog. This blog is created with [**Docusaurus 2 alpha**](https://v2.docusaurus.io/).
12+
13+
<!--truncate-->
14+
15+
This is a test post.
16+
17+
A whole bunch of other information.

blog/2019-05-30-welcome.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
slug: welcome
3+
title: Welcome
4+
author: Yangshun Tay
5+
author_title: Front End Engineer @ Facebook
6+
author_url: https://github.com/yangshun
7+
author_image_url: https://avatars0.githubusercontent.com/u/1315101?s=400&v=4
8+
tags: [facebook, hello, docusaurus]
9+
---
10+
11+
Blog features are powered by the blog plugin. Simply add files to the `blog` directory. It supports tags as well!
12+
13+
Delete the whole directory if you don't want the blog features. As simple as that!

docs/home.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
id: home
3+
title: React Patterns
4+
sidebar_label: Introduction
5+
description: React Patterns, techniques, tips and tricks in development for Ract developer.
6+
keywords: ['reactpatterns', 'react patterns', 'reactjspatterns', 'reactjs patterns', 'react', 'reactjs', 'react techniques', 'react tips and tricks']
7+
version: Introduction
8+
image: /img/reactpatterns-cover.png
9+
slug: /
10+
---
11+
12+
React Patterns, techniques, tips and tricks in development for Ract developer.
13+
14+
To get the latest React patterns follow us on:
15+
16+
* Twitter: <a href="https://twitter.com/reactjspatterns">@reactjspatterns</a>
17+
* Github: <a href="https://github.com/reactpatterns/reactpatterns">@reactpatterns</a>
18+
* Facebook: <a href="https://www.facebook.com/ReactJSPatterns">@reactjspatterns</a>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
---
2+
id: make-the-api-call-in-componentdidmount
3+
sidebar_label: Make the API call
4+
title: Make the API Call in componentDidMount()
5+
description: Make the API call in componentDidMount(), techniques, tips and tricks in development for Ract developer.
6+
keywords: ['make the api call in componentDidMount()', 'reactpatterns', 'react patterns', 'reactjspatterns', 'reactjs patterns', 'react', 'reactjs', 'react techniques', 'react tips and tricks']
7+
version: Make the API call in componentDidMount()
8+
image: /img/reactpatterns-cover.png
9+
---
10+
11+
You should populate data with AJAX calls in the `componentDidMount` lifecycle method. So you can use setState to update your component when the data is retrieved.
12+
13+
For example using Class:
14+
15+
```js
16+
function componentDidMount() {
17+
fetch('api/sms')
18+
.then(result => {
19+
const sms = result.data
20+
console.log('COMPONENT WILL Mount messages : ', sms)
21+
this.setState({sms: [...sms.content]})
22+
})
23+
}
24+
```
25+
26+
For example using Hook:
27+
28+
```js
29+
useEffect(() => {
30+
fetch('api/sms')
31+
.then(result => {
32+
const sms = result.data
33+
console.log('COMPONENT WILL Mount messages : ', sms)
34+
this.setState({sms: [...sms.content]})
35+
})
36+
}, [])
37+
```

docs/mdx.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
id: mdx
3+
title: Powered by MDX
4+
---
5+
6+
You can write JSX and use React components within your Markdown thanks to [MDX](https://mdxjs.com/).
7+
8+
export const Highlight = ({children, color}) => ( <span style={{
9+
backgroundColor: color,
10+
borderRadius: '2px',
11+
color: '#fff',
12+
padding: '0.2rem',
13+
}}>{children}</span> );
14+
15+
<Highlight color="#25c2a0">Docusaurus green</Highlight> and <Highlight color="#1877F2">Facebook blue</Highlight> are my favorite colors.
16+
17+
I can write **Markdown** alongside my _JSX_!

docs/proxy-component.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
id: proxy-component
3+
sidebar_label: Proxy component
4+
title: Proxy Component
5+
description: Proxy Component | React Patterns, techniques, tips and tricks in development for Ract developer.
6+
keywords: ['proxy component', 'reactpatterns', 'react patterns', 'reactjspatterns', 'reactjs patterns', 'react', 'reactjs', 'react techniques', 'react tips and tricks']
7+
version: Proxy Component
8+
image: /img/reactpatterns-cover.png
9+
---
10+
11+
A proxy component is a placeholder component that can be rendered to or from another component. In short a proxy component is a reusable component.
12+
13+
For example:
14+
15+
```jsx
16+
import React from 'react'
17+
18+
class Button extends React.Component {
19+
render() {
20+
return <button type="button">My Button</button>
21+
}
22+
}
23+
24+
class App extends React.Component {
25+
render() {
26+
return <Button />
27+
}
28+
}
29+
30+
export default App
31+
```

docs/stateless-function.md

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
---
2+
id: stateless-function
3+
sidebar_label: Stateless function
4+
title: Stateless Function (Presentational Component)
5+
description: Stateless function (Presentational component) | React Patterns, techniques, tips and tricks in development for Ract developer.
6+
keywords: ['Stateless function', 'statelessfunction', 'presentational component', 'presentationalcomponent', 'reactpatterns', 'react patterns', 'reactjspatterns', 'reactjs patterns', 'react', 'reactjs', 'react techniques', 'react tips and tricks']
7+
version: Stateless function (Presentational component)
8+
image: /img/reactpatterns-cover.png
9+
---
10+
11+
## What is Stateless Function?
12+
13+
* Stateless function is a way to define React components as a function. Rather than as a class or via `React.createClass`.
14+
* Stateless function does not hold state; just props.
15+
16+
## For examples
17+
18+
Without stateless function, write a presentational component that is just renders props, and doesn't has state.
19+
20+
```js
21+
const UserPassword = React.createClass({
22+
render() {
23+
return <p>The user password is: {this.props.userpassword}</p>
24+
},
25+
})
26+
27+
// OR
28+
29+
class Userpassword extends React.Component {
30+
render() {
31+
return <p>The user password is: {this.props.userpassword}</p>
32+
}
33+
}
34+
```
35+
36+
With stateless function.
37+
38+
```js
39+
const UserPassword = function(props) {
40+
return <p>The user password is: {this.props.userpassword}</p>
41+
};
42+
```
43+
44+
With stateless function, arrow function, destructuring and implicit return.
45+
46+
```js
47+
const UserPassword = ({userpassword}) => <p>The user password is: {userpassword}</p>
48+
```
49+
50+
Stateless function is great for styling as well.
51+
52+
```js
53+
const PrimaryButton = props => {
54+
const styles = { background: 'red', color: 'white' }
55+
56+
return <button {...props} style={styles} />
57+
}
58+
```
59+
60+
Stateless function with event handlers.
61+
62+
```js
63+
const Button = props => {
64+
const onClick = e => console.log('You clicked me!')
65+
66+
return <button onClick={onClick}>Click me!</button>
67+
};
68+
```
69+
70+
Stateless function can have defined defaultProps, propTypes.
71+
72+
```js
73+
import PropTypes from 'prop-types'
74+
75+
const UserPassword = props => <p>The user password is: {this.props.userpassword}</p>
76+
77+
UserPassword.propTypes = {
78+
userpassword: PropTypes.string.isRequired,
79+
}
80+
81+
Username.defaultProps = {
82+
username: 'Jonh',
83+
}
84+
```
85+
86+
Stateless function can have defined contextTypes (when using context, it's simply passed in as the second argument).
87+
88+
```js
89+
import PropTypes from 'prop-types'
90+
91+
const UserPassword = (props, context) => <p>User password is {context.password}</p>
92+
93+
WowComponent.contextTypes = {
94+
password: PropTypes.string.isRequired,
95+
}
96+
```

0 commit comments

Comments
 (0)