Skip to content

How to avoid retriggering infinitely? #6

@Boscop

Description

@Boscop

Thanks for making this lib, it seems very useful!

But when I use it like this:

const { useParam } = createParam<{ id: string }>()

export function Screen() {
  const [id] = useParam('id')
  const myId = +id
  const ready = !Number.isNaN(myId);

  const { data, run } = useJsonStreaming<MyStreamType>({
    url: `${process.env.NEXT_PUBLIC_API_URL}/stream`,
    method: 'POST',
    payload: { myId },
    // manual: !enabled,
    manual: true,
  })
  useEffect(() => {
    if (ready) {
      run()
    }
  }, [ready, run])

It seems to retrigger on a re-render, like in an infinite loop.

What's the right way to prevent infinite retriggers (but still only trigger the first time when ready)? :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions