jxom / react-loads

React Loads is a backend agnostic library to help with external data fetching & caching in your UI components.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Optimistic response doesn't apply until after the first render cycle

icopp opened this issue · comments

A simple example:

import useLoads from 'react-loads';

export default function WhateverComponent() {
    const {
        response,
    } = useLoads(({ setResponse }) => {
        setResponse('pre-value')
        return Promise.resolve('value')
    });

    console.log(response);
    return null;
}

The console log will be undefined, then pre-value, then value.

I would expect response to instead be pre-value immediately.

commented

Thanks for logging this. It seems that the 'loading' state gets set before the optimistic response. However, it should obviously ideally get set before. I'll have a look into it when I have the time.