DEV Community

Discussion on: Introducing Isotope - statically-dynamic UI library!

Collapse
 
ilovecharliemey profile image
GabrielFernandes.js

This is really incredible. I am migrating an application to see its behavior in a real case and only one of the resources is not working, which would be setState ({property: value}). in this case, the return of the state forms me null, getState and setState are not working.

const node = view
.child("div", {
state: { color: "#aaa", change: false },
styles: (node) => ({
color: node.getState("color"),
}),
})
.span("TEXT ONE")
.on("click", (target) => {
node.getState("change");
node.setState({ change: true });
console.log(node.getState("change"));
if (target.target.textContent === "TEXT ONE") {
node.text("TEXT TWO");
} else {
node.text("TEXT ONE");
}
});

Collapse
 
areknawo profile image
Arek Nawo

Thanks for feedback! Your error is that you assign the node created by span() method instead of the div() one. Span doesn't have any state and so, you've got null. Simply change the value of your variable, like this:

const node = view.div({
    state: { 
        color: "#aaa",
        change: false
    },
    styles: (node) => ({
        color: node.getState("color"),
    })
});
node.span("TEXT ONE");
node.on("click", () => {
    // ...
});
Collapse
 
ilovecharliemey profile image
GabrielFernandes.js

Thanks ! S2

Collapse
 
ilovecharliemey profile image
GabrielFernandes.js

in this case, the state return is null, getState and setState are not working.*