Skip to content

old data remains rendered after update with error  #4

Closed
@norama

Description

@norama

I have this peace of code:

const ResultSection = ({ text }) => (
    <Async watch={text} promiseFn={() => search(text)}>
        <Async.Loading>Loading...</Async.Loading>
        <Async.Resolved>
            {(data) => (<Result data={data}/>)}
        </Async.Resolved>
        <Async.Rejected>{(error) => `Something went wrong: ${error.message}`}</Async.Rejected>
    </Async>
);

the <Result data={data}/> component remains rendered with the old data after rerunning promiseFn() with new text producing an error, resulting in

<Result data={data}/>
Something went wrong: ${error.message}

I can prevent rendering the old <Result data={data}/> component using this code:

...
<Async.Resolved>
      {(data, { error }) => {return error ? null : (
                <Result data={data} />
       )}}
</Async.Resolved>
...

but I think this is a workaround and the old <Result data={data}/> component should disappear without this explicit check on error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions