question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

onInputTextChanged is triggered without typing after the componentDidMount()

See original GitHub issue

Issue Description

The onInputTextChanged is triggered automatic when the chat view is loaded after componentDidMount( ). I need the onInputTextChanged to display that a user is currently writing to the chat. But always when a users enters a chat the method is fired automatic and it displays that someone is currently writing.

Steps to Reproduce / Code Snippets

this.onTyping = this.onTyping.bind(this); onInputTextChanged={this.onTyping}

Expected Results

onInputTextChanged only fires when a user is currently writing.

Additional Information

  • React Native version: 0.49.5
  • react-native-gifted-chat version: react-native-gifted-chat@0.3.0
  • Platform(s) (iOS, Android, or both?): both

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:5
  • Comments:10

github_iconTop GitHub Comments

5reactions
marcin03commented, Jun 10, 2019

I resolved this by modifying @Huzaifaak method:

constructor(props) {
super(props);
this.state = {isFirstInputTextUpdate:true};
}

firstInputTextUpdate = () => {
this.setState({isFirstInputTextUpdate:false})
}

and in GiftedChat component:

<GiftedChat
onInputTextChanged = {isFirstInputTextUpdate ? this.firstInputTextUpdate : inputText=>updateInputText(inputText)}
//...other props
/>
3reactions
inrecoverycommented, Apr 24, 2020

A clean solution that has worked well for us is to declare an isTyping state that defaults to false. Following this example you can keep logic outside of the render:

const [isTyping, setIsTyping] = useState(false);

Your handler could look something like this:

const onTypingHandler = () => {
    setIsTyping(true);

    isTyping 
      ? startTyping() 
      : endTyping()

    ...the rest the method / reset state ...
 };

And you just call your handler within GiftedChat

<GiftedChat onInputTextChanged={onTypingHandler} ... /> 
Read more comments on GitHub >

github_iconTop Results From Across the Web

Why is componentDidMount not being called when I re-render?
componentDidMount is only called once in the lifecycle of any component, re-render will not reinitialize the component.
Read more >
React Lifecycle Methods Render And ComponentDidMount
When the component file is called it calls the render() method by default because that component needs to display the HTML markup or...
Read more >
Using the Effect Hook - React
They let you use state and other React features without writing a class. The Effect Hook lets you perform side effects in function...
Read more >
How the useEffect Hook Works (with Examples) - Dave Ceddia
Let's look at how to run code after a component mounts ( componentDidMount ), after it re-renders ( componentDidUpdate ), and before it ......
Read more >
How to Solve the Infinite Loop of React.useEffect()
A pitfall you might experience when working with useEffect() is the infinite loop ... the countRef reference is updated without triggering a ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found