Skip to content

Memoize connect response callback functions #1180

@sdemjanenko

Description

@sdemjanenko

I ran into this issue when using the file-upload package, but I think it applies to all components. The code examples

const api = fileUpload.connect(state, send, normalizeProps)

returns a new api object every time a component renders. Ideally this would be memoized so child components can optimize their rendering if they so choose. Memoizing the callback functions separately would also be useful. I ran into an issue where I had code that updated the machine's state if a parent component provided a new value

useEffect(() => {
  api.setFiles(value)
}, [value, api.setFiles])

Because api.setFiles is new every time the component renders, the useEffect gets run (even when the value is unchanged).

I think adding memoization into the connect methods would be really helpful. This probably means the connect methods need to become hooks in React.

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