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

View file

@ -29,13 +29,17 @@ class Home extends React.Component
className="switch-wrapper" className="switch-wrapper"
> >
<Redirect exact from="/" to="/paste/text" /> <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 <Route
exact path="/paste/text" exact path="/paste/text"
component={() => <Pastebin openDialog={@openDialog}/>} render={() => <Pastebin openDialog={@openDialog}/>}
/> />
<Route <Route
exact path="/paste/binary" exact path="/paste/binary"
component={() => <BinaryUpload openDialog={@openDialog}/>} render={() => <BinaryUpload openDialog={@openDialog}/>}
/> />
<Route <Route
path="/paste/:id" path="/paste/:id"