Skip to content

I can't get context to work without a run time error. #1277

Answered by veggie2u
veggie2u asked this question in Q&A
Discussion options

You must be logged in to vote

Destructuring without type-elimation causes this. Take note that useContext can return undefined.

Ah! I wasn't understanding that the error message was coming from the fact that useContext could return undefined. So, how do we fix this? I now see that in the typescript guide it talks about this. It mentions adding a ! to the useFunction. It also says this is bad. Is there a way we could actually get undefined here? Is there a better solution?

I did create a repo with just the SolidJS ts template, and a counter context example here I got the error without the !, and it disappears with it.

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@lxsmnsyc
Comment options

@0bTim
Comment options

Answer selected by veggie2u
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants