question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

Scope

  • 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:

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

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:13 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
CKGraficocommented, Jun 1, 2022

I’m starting to feel like a QA Engineer 👷‍♀️

thanks for all your work and responses to all my questions!

1reaction
PatrickJScommented, Jun 3, 2022

the helpers to convert all of those all live in the react generator so we would have to move all of those to helpers and apply them to every framework

updateStateSetters, updateStateSettersInCode, getUseStateCode https://github.com/BuilderIO/mitosis/blob/main/packages/core/src/generators/react.ts

Read more comments on GitHub >

github_iconTop Results From Across the Web

Executing async code on update of state with react-hooks
This will render a page refresh, and then use the React Ref in the async function. const stateRef = React.useRef().current const [state,setState] ...
Read more >
Steps to Solve Changes Not Reflecting When useState Set ...
What is the useState set method not reflecting a change immediately error? The “useState” hook is one of the in-built hooks in React...
Read more >
Understanding common frustrations with React Hooks
useState inside a function. This will throw the error: React hooks must be called in a React function component or a custom React...
Read more >
5 Most Common useState Mistakes React Developers Often ...
The useState hook is one of many hooks introduced in React, ... define a state and directly update the state using the set...
Read more >
Using the Effect Hook - React
The Effect Hook lets you perform side effects in function components: import React, { useState, useEffect } from 'react'; function Example() { const...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found