commit 61a07e1737134509c6a2e33473b32d8df7c2ea6c
parent 04665e4eb17807332a35591b090edd1b30637330
Author: Matthew Horan <matt@matthoran.com>
Date: Tue, 22 Jan 2019 22:33:55 -0500
Remove getDerivedStateFromProps from LoginForm
Simply reference props in state initializer.
https://reactjs.org/blog/2018/06/07/you-probably-dont-need-derived-state.html#recommendation-fully-controlled-component
Diffstat:
1 file changed, 4 insertions(+), 18 deletions(-)
diff --git a/src/usecase/login/LoginForm.tsx b/src/usecase/login/LoginForm.tsx
@@ -31,26 +31,12 @@ interface State {
class LoginForm extends React.Component<Props, State> {
state: State = {
- hostname: "",
- password: "",
- ssl: true,
- filterBuffers: true
+ hostname: this.props.hostname,
+ password: this.props.password,
+ ssl: this.props.ssl,
+ filterBuffers: this.props.filterBuffers
};
- static getDerivedStateFromProps(nextProps: Props, prevState: State) {
- if (!prevState.hostname && !prevState.password) {
- return {
- ...prevState,
- hostname: nextProps.hostname,
- password: nextProps.password,
- ssl: nextProps.ssl,
- filterBuffers: nextProps.filterBuffers
- };
- } else {
- return null;
- }
- }
-
onPress = () => {
this.props.dispatch({
type: "SET_CONNECTION_INFO",