Skip to content

Allow to display of a "fallback" component #49

@ptitFicus

Description

@ptitFicus

This component is super usefull when fetching data from remote server.

Since such an operation could fail, it would be great to allow the display of a "fallback" component that does not seems to load infinitly, but instead inform the user of the error.

I think it could look like this:

import loader from 'hoc-react-loader'

const Component = ({ users }) => <div>Component {JSON.stringify(users)}</div>
const Fallback = ({ error }) => <div className="error-message">{`Retrieval of users failed with error ${error}`}</div>

export default loader(Component, { wait: ['users'], error: ['error'], fallback: Fallback })

And error could also be specify as a function.

Thoughts?

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions