BuilderIO / BuilderIO/mitosis

BUG: useState hook "set" functions break within onUpdate hook (non-React)

Open
#425 13 comments 0 reactions 1 assignee Claimed by @PatrickJS View on GitHub
angular bug core svelte vue web-components
Dominant language
TypeScript
Stars
14.4k
Forks
671
PR merge metrics
No merged PRs in 30d

Description

**Scope**
- [x] This only impacts specific generators/outputs (please list them here):
svelte

**Describe the bug**
When using `useState` in your builder or in my project, angular is not rendering the correct code.

**To Reproduce**
Steps to reproduce the behavior:
1. Create a useState with get and set.
2. OnUpdate call to the setter.
3. Angular will generate this code, where `setName` does not exist.

[A link to a https://mitosis.builder.io/ fiddle containing the bug:](https://mitosis.builder.io/?outputTab=angular&code=import+%7B+useState%2C+onUpdate+%7D+from+%22%40builder.io%2Fmitosis%22%3B%0A%0Aexport+default+function+MyComponent%28props%29+%7B%0A++const+%5Bname%2C+setName%5D+%3D+useState%28%22Steve%22%29%3B%0A%0A++onUpdate%28%28%29+%3D%3E+%7BsetName%28%27hola%27%29%7D%29%3B%0A%0A++return+%28%0A++++%3Cdiv%3E%0A++++++%3Cinput%0A++++++++css%3D%7B%7B%0A++++++++++color%3A+%22red%22%2C%0A++++++++%7D%7D%0A++++++++value%3D%7Bname%7D%0A++++++++onChange%3D%7B%28event%29+%3D%3E+setName%28event.target.value%29%7D%0A++++++%2F%3E%0A++++++Hello%21+I+can+run+in+React%2C+Vue%2C+Solid%2C+or+Liquid%21%0A++++%3C%2Fdiv%3E%0A++%29%3B%0A%7D)

**Expected behavior**
When using a setter should work.

**Additional context**
I've oppened this to talk about angular but I can see the same in all the libraries except with react, is use state only compatible with react??

update:
see https://github.com/BuilderIO/mitosis/issues/425#issuecomment-1145644830

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.