can you give an example how to use use_context #995
Answered
by
rmorshea
bobwatcherx
asked this question in
Question
-
i have read this http://reactpy.dev/docs/_auto/apis.html#reactpy.core.hooks.create_context |
Beta Was this translation helpful? Give feedback.
Answered by
rmorshea
May 25, 2023
Replies: 1 comment
-
Contexts allow you to pass values between components without doing so directly. from reactpy import create_context, component, html, use_context, run
my_context = create_context(None)
@component
def example():
return my_context(parent(), value=123)
@component
def parent():
return child()
@component
def child():
ctx_value = use_context(my_context)
assert ctx_value == 123
return html.h1(ctx_value)
run(example) |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
rmorshea
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Contexts allow you to pass values between components without doing so directly.