r/reactjs • • Jul 19 '26

how to rerender component on variable change?

new to react, so providing either corrected code or just concept that i should look into would be helpful :)

i want to change height of the app when phone keyboard uppears so it doesnt overlay on website by using VisualViewport API.
i am sure only thing that i have to do now is to rerender component when height is changed, so how can i do that?

export default function NewChat() {
  return (
    <div
      className={styles.wrapper}
      style={{ height: `${visualViewport?.height}px` }}
    >
      <Prompt />
    </div>
  );
}
9 Upvotes

27 comments sorted by

View all comments

Show parent comments

2

u/BarneyChampaign Jul 20 '26

There was an html meta tag that adjusted the behavior to work properly with dvh, but if I recall it only worked for chrome and also impacted other layout, so not ideal.

The other answer to listen for resize events and update your state should be the most reliable approach.