weechatRN

Weechat relay client for iOS using websockets https://github.com/mhoran/weechatRN
git clone http://git.hanabi.in/repos/weechatRN.git
Log | Files | Refs | README | LICENSE

commit 1c3e6dd7f98b85c41025472298a4d8cd9879f2e3
parent 2dc6a3551f996ef6bb1762761566c9528865c340
Author: Matthew Horan <matt@matthoran.com>
Date:   Fri, 25 Sep 2020 17:49:07 -0400

Make UndoTextInput a FunctionComponent

Diffstat:
Msrc/usecase/buffers/ui/UndoTextInput.tsx | 48+++++++++++++++++++-----------------------------
1 file changed, 19 insertions(+), 29 deletions(-)

diff --git a/src/usecase/buffers/ui/UndoTextInput.tsx b/src/usecase/buffers/ui/UndoTextInput.tsx @@ -1,37 +1,28 @@ -import * as React from "react"; +import * as React from 'react'; import { TextInput } from 'react-native'; type Props = React.ComponentProps<typeof TextInput>; -export default class UndoTextInput extends React.PureComponent<Props> { - constructor(props: Props) { - super(props) - this.value = props.value; - } +const UndoTextInput = (props: Props): JSX.Element => { + const { value, onChangeText, ...rest } = props; + const lastValue = React.useRef(value); + const textInput = React.useRef<TextInput>(null); - textInput: TextInput; - value: string; + const handleChangeText = (textValue: string) => { + lastValue.current = textValue; + onChangeText(textValue); + }; - componentDidUpdate() { - const { value } = this.props; - if (value !== this.value) { - this.textInput.setNativeProps({ text: value }) - this.value = value; + React.useEffect(() => { + if (value !== lastValue.current) { + textInput.current.setNativeProps({ text: value }); + lastValue.current = value; } - } + }); - handleChangeText = (textValue: string) => { - this.value = textValue; - this.props.onChangeText(textValue); - } + return ( + <TextInput {...rest} ref={textInput} onChangeText={handleChangeText} /> + ); +}; - render() { - const { value, onChangeText, ...rest } = this.props; - return ( - <TextInput {...rest} - ref={input => this.textInput = input} - onChangeText={this.handleChangeText} - /> - ); - } -} -\ No newline at end of file +export default UndoTextInput;