Websockets on Solidjs
I have some code in React for websocket conexion in components, I tried to port the code to solidjs, but no success yet.
Any idea of how would look this to work correctly? the idea of the websockets is to update an http resource (I think I'll use the mutate of the createResource API)
19 Replies
A nice pattern to use is to put the message into a signal to use it inside an effect.
You can then use
Thanks.
The idea is more to receive the updates via websockets of an initial get via http request.
In that page the client don't get updates.
What's the protocol for the mutation? Are you using some sort of diffing?
I'm trying something like that
but this don't reflect the changes for some reason
there's no reactivity with the component I mean
The resource is updated correctly though
outside the component it renders correctly but inside the component no. I hope I explained that good.
My bad, I was destructuring the component the react way 😅 . It's hard to get used to that part.
There's a babel plugin to fix this problem: https://github.com/orenelbaum/babel-plugin-solid-undestructure
GitHub
GitHub - orenelbaum/babel-plugin-solid-undestructure: A Babel plugi...
A Babel plugin for SolidJS that allows you to destructure component props without losing reactivity. - GitHub - orenelbaum/babel-plugin-solid-undestructure: A Babel plugin for SolidJS that allows y...
I'll check, thanks again!
you can also use
@solidjs-use
which has an awesome WebSocket hook ready to go.I looked into that and don't see the ws hook, how it's called?
Go to their documentation website. The hook is called
useWebSocket
npm
solid-use
A collection of SolidJS utilities. Latest version: 0.7.0, last published: 2 months ago. Start using solid-use in your project by running
npm i solid-use
. There are 9 other projects in the npm registry using solid-use.Do you recomend using this as a global signal or with a context provider ?
What i want to do is to do with the websockets is to update the initial resource of a get request. This will be done in the multiple childs nested on a parent in different nesting levels.
no
solidjs-use
https://solidjs-use.github.io/solidjs-use/getting-started
Unfortunate naming
I see.. it don't appear in the google search
does for me
@solidjs-use
shows right up on npmhmm
strange
@daofficialwizard Anyway the pattern that posted @lexlohr fits the needs of the project i think
Idk if i would do a global signal or a provider but seems to work well
I should probably redo the WebSocket package for solid-primitives. I would probably expose the connection instance.
The api is so well documented. So nice to have the docs with a playground on the side and well structured in the tutorials
cool
sure, they provided a great suggestion 🙂