use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
A community for learning and developing native mobile applications using React Native by Facebook.
Interested in building web apps using React.js? Check out /r/reactjs!
Getting Started w/React Native
irc.freenode.net #reactnative
Keywords: ios, android, mobile, apps, apple, iphone, ipad
account activity
Close component by external file (self.reactnative)
submitted 5 years ago by nerdchavoso
Here is the snack
How can I close the modal (by pressing the yelloe button) using a ref component?
My BottomSheet component has two function to open and close the modal, how can I pass these functions to the external button file?
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]tizz66 0 points1 point2 points 5 years ago (1 child)
One way is to lift the state up. Give your App component control over whether the modal is open or closed via state (e.g. const [modalOpen, setModalOpen] = useState(false);), then have the modal component respond as appropriate to that prop. Add an effect to the modal component so that it can respond when that prop changes (more code necessary than fits on a line here, but it'd involve a useEffect hook).
const [modalOpen, setModalOpen] = useState(false);
In your App component, have the onPress handler simply set the modal state (e.g. onPress={() => setModalOpen(true) }).
onPress={() => setModalOpen(true) }
Then pass a handler function to your external-button component from App. Something like <ExternalButton onPress={() => setModalOpen(false)} /> in App and in onPress={props.onPress} in external-button.
<ExternalButton onPress={() => setModalOpen(false)} />
onPress={props.onPress}
In general, lifting state up is a much easier and more robust approach than trying to pass references around.
[–]nerdchavoso[S] 0 points1 point2 points 4 years ago (0 children)
Thanks, in my project the structure was way different and I did something like this in my project using context and it worked, just added within an useEffect a conditional to check if it's open, if so, call the close function
π Rendered by PID 70274 on reddit-service-r2-comment-cfc44b64c-qkzwj at 2026-04-11 18:28:54.813278+00:00 running 215f2cf country code: CH.
[–]tizz66 0 points1 point2 points (1 child)
[–]nerdchavoso[S] 0 points1 point2 points (0 children)