home: do not re-render child when parent is re-rendered

This commit is contained in:
Peter Cai 2020-02-19 11:15:16 +08:00
parent 182c225528
commit d2957f3b2c
No known key found for this signature in database
GPG Key ID: 71F5FB4E4F3FD54F
1 changed files with 6 additions and 2 deletions

View File

@ -29,13 +29,17 @@ class Home extends React.Component
className="switch-wrapper"
>
<Redirect exact from="/" to="/paste/text" />
{
# Use `render` instead of `component` to prevent re-rendering the child
# when parent is re-rendered (however this prevents passing match props)
}
<Route
exact path="/paste/text"
component={() => <Pastebin openDialog={@openDialog}/>}
render={() => <Pastebin openDialog={@openDialog}/>}
/>
<Route
exact path="/paste/binary"
component={() => <BinaryUpload openDialog={@openDialog}/>}
render={() => <BinaryUpload openDialog={@openDialog}/>}
/>
<Route
path="/paste/:id"