Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typescript-class component toast message in modal usage #172

Closed
tarikfp opened this issue Apr 8, 2021 · 9 comments
Closed

Typescript-class component toast message in modal usage #172

tarikfp opened this issue Apr 8, 2021 · 9 comments
Labels
bug Something isn't working v2 Bug fixed / feature added in v2

Comments

@tarikfp
Copy link

tarikfp commented Apr 8, 2021

issue

Hello. I wanted to use toast message in a modal. I initialized the steps related to showing in modal as shown in docs. But having problem while creatingRef. What should be the proper way to use toast message in typescript- class component ?

The error is shown in screenshot above. Any help would be great. Thanks...

@tarikfp tarikfp changed the title Typescript modal usage Typescript-class component toast message in modal usage Apr 8, 2021
@tarikfp
Copy link
Author

tarikfp commented Apr 8, 2021

Other attempt...

issue2
...

@calintamas
Copy link
Owner

calintamas commented Apr 9, 2021

Hi @tarikpnr , try creating a ref in the class constructor using React.createRef

constructor(props) {
  super(props);
  this.modalRef = React.createRef();
}

@tarikfp
Copy link
Author

tarikfp commented Apr 10, 2021

Screenshot_1

Im guessing in order to access the functions of Toast I need to specify a type to it.

Screenshot_2

Currently if I try to use toast message on modal private readonly modalRef:any having any type (workaround)...
And still I don't get any proper toast message on top of the modal. It shows up on top of the screen for a split-second, then it disappears.

The way I use the show function is shown below;

Screenshot_3

@tarikfp
Copy link
Author

tarikfp commented Apr 10, 2021

Screenshot_4

When I specify zIndex of both Modal and Toast component, the toast message shows up. But I am not able to hide it by pressing on it. So Im thinking that I might be missing someting with the refs ? And which type exactly I need for the modalRef ?

Screenshot_5

@calintamas
Copy link
Owner

@tarikpnr to hide it, you need to call hide on the same ref

this.modalRef.current.show({
  ...
  onPress: () => this.modalRef.current.hide()
})

As for creating the ref, you can set it to be of Toast type:

this.modalRef = React.createRef<Toast>();

@tarikfp
Copy link
Author

tarikfp commented Apr 11, 2021

this.modalRef.current.hide() that did the trick! Thanks.

But on the other side, while setting type to React.createRef(), still getting error below.

Screenshot_1

Screenshot_3

@jailsonpaca
Copy link

1+, I am with the same problem

@Onibenjo
Copy link

Onibenjo commented May 8, 2021

To fix the typescript error, i just created a variable and in the ref, added

// doing this for autocompletion, could be set to null
let modalToastRef  = Toast

// then set the variable to the ref
<Toast ref={ref => (modalToastRef = ref)} />

@calintamas calintamas added bug Something isn't working v2 Bug fixed / feature added in v2 labels Oct 15, 2021
@calintamas
Copy link
Owner

Fixed in v2.0.0. Read the complete changelog.

If you find any issues with the v2 implementation, feel free to reopen this issue. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working v2 Bug fixed / feature added in v2
Projects
None yet
Development

No branches or pull requests

4 participants