Skip to content

Commit d99c077

Browse files
committed
UserStatusScreen [nfc]: Make statusText state a string
UserStatusScreen has undertaken to use Input as a controlled input, where at all times it's telling the Input what `value` it should have. https://reactjs.org/docs/forms.html#controlled-components It seems like the responsible thing for UserStatusScreen to do, for clarity, is to at least store the value meant for `value` in a proper state variable. We'll solidify that role with a rename, coming next.
1 parent 8e516b6 commit d99c077

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/user-statuses/UserStatusScreen.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export default function UserStatusScreen(props: Props): Node {
4343
const ownUserId = useSelector(getOwnUserId);
4444
const userStatusText = useSelector(state => getUserStatus(state, ownUserId).status_text);
4545

46-
const [statusText, setStatusText] = useState<string | null>(userStatusText);
46+
const [statusText, setStatusText] = useState<string>(userStatusText ?? '');
4747
const _ = useContext(TranslationContext);
4848

4949
const sendToServer = useCallback(
@@ -59,7 +59,7 @@ export default function UserStatusScreen(props: Props): Node {
5959
}, [statusText, sendToServer]);
6060

6161
const handlePressClear = useCallback(() => {
62-
setStatusText(null);
62+
setStatusText('');
6363
sendToServer({ status_text: null });
6464
}, [sendToServer]);
6565

@@ -70,8 +70,8 @@ export default function UserStatusScreen(props: Props): Node {
7070
maxLength={60}
7171
style={styles.statusTextInput}
7272
placeholder="What’s your status?"
73-
value={statusText ?? ''}
74-
onChangeText={text => setStatusText(text || null)}
73+
value={statusText}
74+
onChangeText={setStatusText}
7575
/>
7676
<FlatList
7777
data={statusSuggestions}

0 commit comments

Comments
 (0)