useOnNetworkChange
useOnNetworkChange is used to register events for network change actions. If you want to refresh the page, or update any state on network change, you can use this hook.
You should know that every usage of this hook registers an event for network change. Calling this hook once is enough to register any event that you want.
import { useOnNetworkChange } from "ethylene/hooks";
function App() {
useOnNetworkChange(() => window.location.reload()); //Refresh the page on network change
return (
...
);
}
You can also send dependency array as second parameter to this hook to reregister the event on state updates.
import { useOnNetworkChange } from "ethylene/hooks";
import { useState } from "react"
function App() {
const [value, setValue] = useState(0)
// Reassign the event when value changes
useOnNetworkChange(() => window.location.reload(), [value]);
return (
...
);
}
API
args: (
/* Callback function that you want to execute on network change*/
callback: () => void,
/* Dependency for reassigning events */
deps: any[]
)