Skip to content

Setting a new array doesn't trigger an update #76

Closed
@bluedot74

Description

@bluedot74

Hi,

I created a codesandbox to demonstrate the issue: https://codesandbox.io/s/valtio-simple-counter-forked-17yos?file=/src/App.js

Given a state like:

const state = proxy({ arr: ["hello"] });

Then accessing the array like so:

const list = useProxy(state.arr);

I would expect the component to rerender when I do something like this:

const handleClick = () => {
    state.arr = ["hello", "world"];
  };

However, it doesn't update.
It does update if I mutate the list like this: state.arr.push("world");.
But assigning a whole new array doesn't cause an update.

Am I just misunderstanding how it's supposed to work or is this a bug?

Thanks!

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