Skip to content

Commit

Permalink
Change example
Browse files Browse the repository at this point in the history
  • Loading branch information
mathiasbergqvist committed Mar 3, 2021
1 parent 7afb622 commit 042c85c
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion react-examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
//MyComponent.js
import React from "react";

const MyComponent = ({ title, content }) => {
// const MyComponent = ({ title, content }) => {...
const MyComponent = (props) => {
const { title, content } = props;
return (
<div>
<h2>{title}</h2>
Expand Down Expand Up @@ -63,6 +65,31 @@ const ComponentWithState = () => {
export default ComponentWithState;
```

## useEffect

```javascript
import React, { useEffect } from "react";

const UseEffectComponent = () => {
const [count, setCount] = useState(0);

useEffect(() => {
// Update the document title using the browser API
document.title = `You clicked ${count} times`;
}, []);

return (
<div>
<p>You clicked {count} times</p>
<button onClick={() => setCount(count + 1)}>
Click me
</button>
</div>
};

export default ComponentWithState;
```
## User events
```javascript
Expand Down

0 comments on commit 042c85c

Please sign in to comment.