fix: Props event not updating internal value

Signed-off-by: Avior <f.bouillon@aptatio.com>
This commit is contained in:
Florian Bouillon 2022-09-28 14:47:15 +02:00
parent c92dc2d736
commit cd2304de17
Signed by: Florian Bouillon
GPG Key ID: E05B3A94178D3A7C

View File

@ -120,7 +120,11 @@ export default class Input extends React.PureComponent<Props, States> {
}
}
public async componentDidUpdate(_: Props, prevStates: States) {
public async componentDidUpdate(prevProps: Props, prevStates: States) {
if (prevProps.value !== this.props.value) {
this.onChange(this.props.value?.toString() ?? '')
}
if (prevStates.value !== this.state.value) {
if (this.props.onValue) {
this.props.onValue(this.state.value ?? '')
@ -354,16 +358,16 @@ export default class Input extends React.PureComponent<Props, States> {
* handle the change event of the input
* @param event the event
*/
private onChange = async (event: React.ChangeEvent<HTMLInputElement>) => {
private onChange = async (event: React.ChangeEvent<HTMLInputElement>|string) => {
// get the input
const value = event.currentTarget.value
const value = typeof event === 'string' ? event : event.currentTarget.value
// console.log("onChange", value)
if (typeof value !== 'string') {
return
}
if (this.props.onChange) {
if (this.props.onChange && typeof event !== 'string') {
this.props.onChange(event)
}