Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

useKeyboard cause re-render many time #307

Open
chukiatt opened this issue May 9, 2022 · 4 comments
Open

useKeyboard cause re-render many time #307

chukiatt opened this issue May 9, 2022 · 4 comments

Comments

@chukiatt
Copy link

chukiatt commented May 9, 2022

const keyboard = useKeyboard()

this hook cause re-render all component too many on keyboard show and dismiss

after remove it, my app is working properly not re-render on keyboard show and hide

it work fine in android but not work in iOS

could you fixed this hook.

thank you very much

@LinusU
Copy link
Member

LinusU commented May 30, 2022

The hook needs to trigger a re-render when it updates the value that it returns, otherwise your component wouldn't be able to use the updated value?

Or do you mean that it triggers multiple re-renders when the keyboard is shown/hidden, instead of one?

Could you post a snack that shows the problem?

@fukemy
Copy link

fukemy commented Jul 25, 2022

yes very noise problem, my chatscreen have large data, so i want to avoid re-render too many time

@flexsurfer
Copy link

yes it triggers at least twice with the same values

@DawitAskabe
Copy link

DawitAskabe commented May 25, 2023

this is happening to me on RN 0.66.5. Check your version and update us. I am not using keyboard hook from this library, i have same event handler implementation as the hook in my code(shown bellow).

I tried the keyboard hook from this library and it did same thing so i stayed with my implementation.

In the following code If i comment out the state set calls, keybaord shows up and stays. If i try to update state in the event handlers the keyboard just shows for brief moment and hides right away (the state change caused refresh). This is the behavior on RN 0.66.5 which im locked on.

Same code in RN version "0.70.4" works. If anyone have insight how i can go around this issue on 0.66.5 let me know.

 useEffect(() => {
    const keyboardWillShowListener = Keyboard.addListener('keyboardDidShow', e => {
      setIsKeboardOpen(true);
      setchildHeight(childHeight + heightOfKeybaordHeight);
    });
    const keyboardWillHideListener = Keyboard.addListener('keyboardDidHide', e => {
      setIsKeboardOpen(false);
      setchildHeight(childHeight - heightOfKeybaordHeight);
    });

    return () => {
      keyboardWillHideListener.remove();
      keyboardWillShowListener.remove();
    };
  }, []);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants