-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
d2d33b6
commit d0c60fd
Showing
2 changed files
with
68 additions
and
1 deletion.
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
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,32 @@ | ||
# React Cheatsheet | ||
|
||
## How do I declare a component? | ||
|
||
### Function Component | ||
```jsx | ||
const MyComponent = ({ name }) => { | ||
return (<p>Hello { name }</p>) | ||
} | ||
``` | ||
|
||
### Class Component | ||
```js | ||
class MyComponent extends React.Component { | ||
render() { | ||
return (<p>Hello { this.props.name }</p>) | ||
} | ||
} | ||
``` | ||
|
||
## Sending / receiving props | ||
|
||
Props can be sent as key-value pairs using XML-style syntax: | ||
```jsx | ||
<MyComponent name='Amy' /> | ||
``` | ||
|
||
An object can be 'spread' to send the whole thing as the props: | ||
```jsx | ||
const props = { name: 'Amy' }; | ||
return (<MyComponent { ...props } /> | ||
``` |