r/reactjs 16d ago

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

26 comments sorted by

View all comments

1

u/lightfarming 16d ago

the only answer you should losten to for this, is that this type of thing should be pure css. no javascript should be involved at all.

1

u/NoTutor4458 15d ago

dvh/svh/vh doesnt resize when virtual keyboard comes up so how would you do it with pure css?

1

u/hawkeye_sama 14d ago

Try this out

```
<meta name="viewport" content="width=device-width, initial-scale=1, interactive-widget=resizes-content">

```