testshallpass / react-native-dropdownalert

An alert to notify users about an error or something else
MIT License
1.86k stars 253 forks source link

Globally accessing dropDownAlert ref #206

Closed kadanes closed 5 years ago

kadanes commented 5 years ago

Short Description

I want to use this component globally from all my other components. So I decided to define it within my App component and set its ref to a global variable which I exported. But I could not access it from the other components, where it shows as undefined.

Steps to Reproduce / Code Snippets / Usage

export let dropDownAlertRef: DropdownAlert;

export default class App extends React.Component<any, any> {
  render() {
    return (
      <Provider store={store}>
        <DropdownAlert
          ref={(ref) => {
            dropDownAlertRef = ref as DropdownAlert;
          }}
        />
        <Navigator />
      </Provider>
    );
  }
}

Expected Results

Access the exported ref from other files so I can directly call the alert showing function.

Additional Information

ardyfeb commented 5 years ago

the readme already have an example https://gist.github.com/testshallpass/6c6c867269348c485a1e0d6ae3f55e90

testshallpass commented 5 years ago

Yes, checkout Caveats section for examples.