Can you share your (anonymized/non-sensitive) code for this ? What is exactly your variable composed of ? Is it an array or an object ? What are you deleting : fields of the objects or elements of an array ? So when you delete the last element, what do you get : an empty array, an empty object, no array or no object ?
– ZettaP
Aug 9, 2023 at 6:48
- Hi @ZettaP, in this case, my variable is an object, but I encounter a similar problem with a string in another project. When I reinit the variable (by deleting all its key or create an empty object/string), a log in js of code sandbox show me the good variable content (i.e nothing), but not handlebar in Slate which always show me the last key/string, as if it keep cache. However, if I had a new key/string, everything is good, only the last element is visible.
– Turvy
Aug 9, 2023 at 8:23
Is your initial array empty ? Are you setting the value of your variable to what it is originally in the template ? What happens if you were to change the initial value ? (like instead of starting from or {}, start from undefined)
– ZettaP
Aug 9, 2023 at 11:01
Hurray!!! that works now. The initial variable was initiated with an empty object, but I’m just trying with null instead (undefined was not accepted) and it works fine. When deleting the last key, handlebar show me an emty object
– Turvy
Aug 9, 2023 at 11:45
- Added as a real answer, as it seems that’s a viable workaround
Glad that it worked !
– ZettaP
Aug 10, 2023 at 6:25
Add a comment
2 Answers
Sorted by:
2
As a workaround, you can initialize your template with a value different than what is the “empty state” you might encounter during the standard operation of the app.
For instance, if you have an array, which you push and delete elements from, initialize it by an empty value (null
, for instance) instead of empty array ([]
).
For an object, initialize it as well by undefined, null, instead of empty object ({}
).
Share
Improve this answer
Follow
answered Aug 10, 2023 at 6:25
![ZettaP's user avatar](https://answers.ontologize.com/uploads/default/original/1X/f6572b2884cd4758a91934f1ba53474291ab55a3.png)
ZettaP
84988 silver badges1212 bronze badges
Add a comment
0
When deleting the element, I would suggest explicitly setting the variable state to an empty object (or whatever you want it to be) using the SlateFunctions.setstate()
method (docs).
Share
Improve this answer
Follow
answered Aug 3, 2023 at 17:12
![Ontologize's user avatar](https://answers.ontologize.com/uploads/default/original/1X/22094914c4e95252fa7d28111a1d01cd86621115.png)
Ontologize
62911 silver badge77 bronze badges
- I’ve already done that, mais with the same result. Strangely, when I add a new element again, the state variable is good
– Turvy
Aug 4, 2023 at 7:53
Answer originally provided by Ontologize on Stack Overflow: codesandbox - Palantir Slate: state give different value in Code sandbox and handlebar - Stack Overflow