Replies: 3 comments 4 replies
-
@rmorshea I just asked @jkrobicki to check because I am not sure if this is intended behavior, if it is I could write some docs to explain why it happens. |
Beta Was this translation helpful? Give feedback.
-
This might be a bug. I would've expected the code below to resolve the infinite looping... but ironically it doesn't. @component
def parent():
a, set_a = idom.hooks.use_state("")
return child(a, set_a)
@component
def child(a, set_a):
if a != "test":
set_a("test")
print("function call")
return html.p("test")
run(parent) |
Beta Was this translation helpful? Give feedback.
-
The originally posted code snippet is intended behavior. It happens because:
I've never seen any reason why someone would want to set a value as they are rendering. This is because, as soon as one view renders, the next one will begin. Typically this leads to the view flashing from one thing to the next so fast that it's unreadable. If you need to set something after rendering (usually to load some resource from a database that may take some time to respond), you'd do that in an "effect". |
Beta Was this translation helpful? Give feedback.
-
Description:
How can I set state in
child
function? With my code it triggers infinite loop.Beta Was this translation helpful? Give feedback.
All reactions