Make a method similar to React.Component.forceUpdate()
See original GitHub issueIs 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:
- Created 4 years ago
- Reactions:4
- Comments:8 (4 by maintainers)
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
By the way, do I understand correctly that a
tick()
should ALWAYS return an initially unresolved promise?