Initial state is no longer passed to hook. It will be always set to null
.
// before
const [data, error] = useSSE(
{ data: 'initial data' }
() => {
return fetch();
},
[]
);
// after
const [data, error] = useSSE(() => {
return fetch();
}, []);
Errors are returned separately from data.
// before
const [data] = useSSE();
// if error happend data.isError was true
// now
const [data, error] = useSSE();
// error has all error details
If effect does not resolve before timeout error will be returned. Timeout value can be added to resolveData
function.
This version comes with breaking changes. Versions 0.x.x
are not compatible.
key
param is no longer needed,- name of global variable is now customizable,
- seperation of data an internal contexts.
Migration from 0.x.x
consists in removing key
param from the useSSE
hook calls:
// before
const [data] = useSSE(
{},
"my_key",
() => {
return fetch();
},
[]
);
// after
const [data] = useSSE(
{},
() => {
return fetch();
},
[]
);