heroku / heroku/react-refetch

Allow returning a `null` mapping from a lazy fetch?

Open
#164 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
3.4k
Forks
137
PR merge metrics
No merged PRs in 30d

Description

Hey, I'm looking at a use case that isn't covered currently. I've got a handful of different lazy fetches on a settings page, and a few of them are "dangerous" such that they require user confirmation. I was thinking it would be really nice to be able to do:

```js
function confirmAndDeleteField(field) {
const yes = window.confirm(`Are you sure you want to delete the "${field.name}" field?`)
if (!yes) return null
return {
url: `/api/fields/${field.id}`,
method: `DELETE`,
then: () => ...
}
}
```
```js
...
this.props.confirmAndDelete(field)}
```

But right now "aborting" the lazy fetch before it starts by returning `null` throws an error.

I realize I could solve this by adding a separate function to the view itself, and handling the confirm there, and then calling into the `props.` function afterwards. But it feels like added complexity, when `return null` feels like an elegant solution.

What do you think @ryanbrainard?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.