Network api really shine if you want to show content based on network connection of user. For example you can provide high resolution image if user are connected with high bandwidth or low resolution if not better connection available.
Solidjs will provide you lightweight reactive environment with extreme speed of web without diffing any Virtual DOM into your web app. Solidjs works on the principle of fine grained reactivity .
We will create a useNetwork hook that will take care of registering events on mount related to network status and remove on cleanup.
onMount and onCleanup is a life cycle function in solidjs . onMount run when your component mount and onCleanup function run when your component unmount.
Here we have created a store using createStore function which take initial value and return a read and write tuple.
isOnline field will track the current user network and store boolean value. You can test this by changing network status to offline in dev tools > Network.
type field contain the type of connection a device is using to communicate with the network like wifi.
effectiveType contain type of network connection like 3g , 4g etc...
downlink contain the effective bandwidth estimate in megabits per second, rounded to the nearest multiple of 25 kilobits per seconds.
rtt contain the estimated effective round-trip time of the current connection, rounded to the nearest multiple of 25 milliseconds.
saveData contain boolean value like true if the user has set a reduced data usage option on the user agent.
Lets utilise useNetwork hook in App.jsx. I have added nice UI using Hope UI.
Those templates dependencies are maintained via pnpm via pnpm up -Lri.
This is the reason you see a pnpm-lock.yaml. That being said, any package manager will work. This file can be safely be removed once you clone a template.