How to recover scroll bar position with Show?
I'm using <Show> to render component.
The component has scroll bar.
But when I re-render if <Show when = { true } >
I lost scroll bar position.
17 Replies
my two solution ideas:
1. You could probably just hide the component with display:none instead of conditionally rendering component
2. cache the previous scroll position onClenaup and reset it onMount
2nd solution is much better...I'll try it out thanks..
I'm trying 2nd solution, but it's not working. Can't I put signal inside?
It seems when component is re-rendered by Show, the signal value goes 0.
Does it re-create signal,too?
![](https://utfs.io/f/5b724cc3-384b-4af5-92d3-958fdf2a34c0-1nq2cb.png)
Does it re-create signal,too?yup
createSignal
is pretty much like new Array()
, new data instanceIsn't Solid component function called once? not like React
But Show unmounts it
Then, Should I put signal outside function?
not sure if you need a signal at all
just store the position in a variable
Global variable?
if this component can be mounted in multiple places at once, you probably should manage the cache by a key or something, but just a
let
variable that you udpate is fineThen, it's not re-usable component, whenever I use this component, I need to declare global variable..
you can re-use the variable too
but you can also use the parent component for that
Is there no way to put any storable variable inside function in unmountable component ?
if you don't unmount the component, there is no problem
but you unmount it and then mount a compleately new instance of it
there are ways to solve it, but you need to have a link between diffferent component instances, it doens't self-contain the state anymore
Ok, So If we use <Show>, the component function will be called like React right?