Dragging rectangles impossible? (tried to build a timeline component)

Hey, I wanted to build a timeline component where you could drag divs left and right with your mouse. It would be stored in a state and the rectangles would be rendered using For. However, it seems like something like that is impossible. At first, I tried to set the state like in react by basically taking the object that defines the dragged box, making a copy of it by spreading its contents, setting the new values, and assigning it back to the array in a map function that would replace the original object by index. That resulted in the rectangle component being unmounted immediately. So I tried preserving the references. That kind of worked but it does not re-render the list during the changes but only after the rectangle component changes its dragged state to false. Please, look at this example. Try dragging the rectangles and see what I mean. https://playground.solidjs.com/anonymous/2e4da24a-a2bd-4f87-abc4-5553d3f288af How should I approach this properly to make things re-render while dragging?
Solid Playground
Quickly discover what the solid compiler will generate from your JSX template
4 Replies
nerotide
nerotide7mo ago
Wow thank you, that was simpler than I thought. I am now a little confused about when should I use signals. Are signals supposed to be used for primitive values like numbers, strings, and booleans and not things like arrays or objects? I mean like you always want your UI to react to any state changes and if signals can't do that, why should I use them?
mdynnl
mdynnl7mo ago
kindly take the time to read this up and continue to next tutorial
thisbeyond
thisbeyond7mo ago
Solid Drag & Drop
A lightweight, performant, extensible drag and drop toolkit for Solid.
Want results from more Discord servers?
Add your server
More Posts