React-native-paper: Call components as methods

Created on 7 May 2020  路  2Comments  路  Source: callstack/react-native-paper

Is it possible to call some components as methods?

For example, I wish I could call: Banner.show({...props}), Dialog.show({...props}), Modal.show({...props}) and Snackbar.show({...props}), so I can fire it easily on callbacks, etc.

Is there any example or advice to achieve something like that?

Thanks!

Stale question

Most helpful comment

Not that I could find: I ended up creating a react context and mounting that at the root of my app components, to render a Snackbar when triggered globally.

This allowed me to use the context from anywhere in my codebase, to dispatch an action via the reducer on the global react context I made, and have the state change so that the snackbar component was rendered.

I think the same concept could be applied to the other components.

Snack example showing the provider at the root, the custom component inside the provider, and a child component using the global react context to dispatch an action that ultimately changes the state on the snackbar component to be presented.

https://snack.expo.io/@macfanatic/react-native-paper-snackbar-provider

All 2 comments

Not that I could find: I ended up creating a react context and mounting that at the root of my app components, to render a Snackbar when triggered globally.

This allowed me to use the context from anywhere in my codebase, to dispatch an action via the reducer on the global react context I made, and have the state change so that the snackbar component was rendered.

I think the same concept could be applied to the other components.

Snack example showing the provider at the root, the custom component inside the provider, and a child component using the global react context to dispatch an action that ultimately changes the state on the snackbar component to be presented.

https://snack.expo.io/@macfanatic/react-native-paper-snackbar-provider

Hello 馃憢, this issue has been open for more than 2 months with no activity on it. If the issue is still present in the latest version, please leave a comment within 7 days to keep it open, otherwise it will be closed automatically. If you found a solution on workaround for the issue, please comment here for others to find. If this issue is critical for you, please consider sending a pull request to fix the issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

knobandre picture knobandre  路  4Comments

zachariahtimothy picture zachariahtimothy  路  3Comments

kpervin picture kpervin  路  3Comments

mihaidaviddev picture mihaidaviddev  路  3Comments

talaikis picture talaikis  路  3Comments