Skip to content

[enhance] use the latest version of the config callbacks #515

@Lam9090

Description

@Lam9090

Related issue: #508

Currently,the config callbacks captured by the eventsRef is the callbacks created in the initial render of the component.
If the config callbacks is pure, everything is fine.
but if the config callbacks rely on some variables of the components , it would cause some bugs related to the stale closure.

solution

I think if the useSWR hook read the config callbacks via useRef would be great, but this may bring some bugs if some APP rely on the current behavior of the config callbacks.

  const eventsRef = useRef({
    emit: (event, ...params) => {
      if (unmountedRef.current) return
      configRef.current[event](...params)
    }
  })

what do you think?

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