Skip to content

Commit dae9a66

Browse files
pedroapfilhoKent C. Dodds
authored andcommitted
refactoring asFragment example to use hooks (testing-library#193)
1 parent 79b149a commit dae9a66

File tree

1 file changed

+8
-14
lines changed
  • docs/react-testing-library

1 file changed

+8
-14
lines changed

docs/react-testing-library/api.md

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -226,23 +226,17 @@ Returns a `DocumentFragment` of your rendered component. This can be useful if
226226
you need to avoid live bindings and see how your component reacts to events.
227227
228228
```jsx
229+
import React, { useState } from 'react'
229230
import { render, fireEvent } from '@testing-library/react'
230231

231-
class TestComponent extends React.Component {
232-
constructor() {
233-
super()
234-
this.state = { count: 0 }
235-
}
236-
237-
render() {
238-
const { count } = this.state
232+
const TestComponent = () => {
233+
const [count, setCounter] = useState(0)
239234

240-
return (
241-
<button onClick={() => this.setState({ count: count + 1 })}>
242-
Click to increase: {count}
243-
</button>
244-
)
245-
}
235+
return (
236+
<button onClick={() => setCounter(count => count + 1)}>
237+
Click to increase: {count}
238+
</button>
239+
)
246240
}
247241

248242
const { getByText, asFragment } = render(<TestComponent />)

0 commit comments

Comments
 (0)