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.

Make a method similar to React.Component.forceUpdate()

See original GitHub issue

Is your feature request related to a problem? Please describe. Sometimes I need to immediately update the state of a component. For example, in order to measure its dimensions when mounting, and then apply some logic to these sizes, for example, position it on the page. This is now impossible to do.

Describe the solution you’d like I see a solution in creating a method similar to React.Component.forceUpdate().

Describe alternatives you’ve considered Using the tick() method, but it does not seem to work as needed - in some cases it returns an already resolved promise.

How important is this feature to you? Pretty important. Now we are in the stage of choosing a framework on which we will begin a new project. The lack of such functionality will be very undesirable.

Additional context Example: the Carousel component with a smooth scroll (via CSS-transition) and an Item that should be central, for example, with an index of 41 out of 100. The layout is adaptive.

I need to mount the component on the page, measure the offset of the Item with index 41, scroll the Carousel to it, and only then turn on the animations.

Now scrolling to Item and animations are turned on simultaneously, which is why initial scrolling to the 41st Item occurs with animation.

Using the forceUpdate() method will allow me to first scroll up to 41st Item, and only then enable animations.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:4
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
pngwncommented, Sep 8, 2019

Can’t you simply wait for the changes to be flushed and then wait for a few frames before enabling the animations?

https://svelte.dev/repl/833c8b3aa2af456cbdb9f1adad7295b6?version=3.10.0

0reactions
Alexey-Schcommented, Sep 9, 2019

By the way, do I understand correctly that a tick() should ALWAYS return an initially unresolved promise?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Force Update a React Component - Stack Abuse
The class component has a built-in method for re-rending a component, called forceUpdate() , which is used to force a component to re-render....
Read more >
React.Component
shouldComponentUpdate() is invoked before rendering when new props or state are being received. Defaults to true . This method is not called for...
Read more >
React - How to force a function component to render?
I used a third party library called use-force-update to force render my react functional components. Worked like ...
Read more >
How and when to force a React component to re-render
In any user or system event, you can call the method this.forceUpdate() , which will cause render() to be called on the component,...
Read more >
ReactJS forceUpdate() Method - GeeksforGeeks
ReactJS forceUpdate() Method ... The components in React will re-render only if the state of the component or the props passed to it...
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