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() {
|
||||
const todos = this.getTodos();
|
||||
|
||||
return (
|
||||
<div className="App" >
|
||||
<Form
|
||||
onSubmit={text => this.setTodos([{ text, complete: false }, ...this.getTodos()])}
|
||||
onSubmit={text => this.setTodos([{ text, complete: false }, ...todos])}
|
||||
/>
|
||||
<div>
|
||||
{this.getTodos().map(({ text, complete }, i) => (
|
||||
{todos.map(({ text, complete }, i) => (
|
||||
<div
|
||||
key={text}
|
||||
onClick={() => this.toggleComplete(i)}
|
||||
|
||||
Reference in New Issue
Block a user