mirror of
https://github.com/bendtherules/react-hooks-with-class.git
synced 2026-08-18 13:53:06 +00:00
Call getTodos only once in render
This commit is contained in:
+4
-2
@@ -46,13 +46,15 @@ export default class App extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
const todos = this.getTodos();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="App" >
|
<div className="App" >
|
||||||
<Form
|
<Form
|
||||||
onSubmit={text => this.setTodos([{ text, complete: false }, ...this.getTodos()])}
|
onSubmit={text => this.setTodos([{ text, complete: false }, ...todos])}
|
||||||
/>
|
/>
|
||||||
<div>
|
<div>
|
||||||
{this.getTodos().map(({ text, complete }, i) => (
|
{todos.map(({ text, complete }, i) => (
|
||||||
<div
|
<div
|
||||||
key={text}
|
key={text}
|
||||||
onClick={() => this.toggleComplete(i)}
|
onClick={() => this.toggleComplete(i)}
|
||||||
|
|||||||
Reference in New Issue
Block a user