Skip to content

[Proposal/Discussion] How to improve indicate method #758

@AlbertSabate

Description

@AlbertSabate

Describe the bug
Following the brisa example as it is, it does not work.

To Reproduce
Just follow the docs.

https://brisa.build/api-reference/components/request-context#indicate

Expected behavior
When using indicator, that label should only show when the action is pending state.

I also would like to have a way to be able to disable a button when a server action is in pending state.

API Change proposal.

Would not it be better to have something like:

const someAction = indicate(() => { action logic });

return (<>
  <button onClick={someAction}>Happy Days</button>
  {someAction.pending ? 'Action is Loading' : 'Action is loaded or not been triggered'}
</>);

The API could have the following: pending, ready, error, reset().
Problems I could think: What happen if you need to call the action multiple times?
In this case maybe we could add an id when throwing the action or proposing something like: someAction('id'). Then someAction will default to no id. And if we call someAction('...') it will contain the id. or to have it standard, maybe we could: someAction().

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions