cassette: ContextProvider/Consumer not working as expected
Hi @benwiley4000,
Thanks so much for your awesome work!
I’ve had to rig up my own context provider that wraps the component because, well, I just can’t get the one included in your component to work!
Can you please help me understand? Should it not be simply a matter of:
import { PlayerContextProvider } from '@cassette/core';
import { MediaPlayer } from '@cassette/player';
...
<PlayerContextProvider>
<MediaPlayer/>
</PlayerContextProvider>
And then, elsewhere:
import { PlayerContextConsumer } from '@cassette/core';
...
<PlayerContextConsumer filterList={['currentTime', 'paused', 'onTogglePause']}>
{({ currentTime, paused, onTogglePause }) => (
<div>
The track is {paused ? 'paused' : 'playing'}. The time is {currentTime}.
</div>
)}
</PlayerContextConsumer>
Frustratingly, this creates:
TypeError: Cannot read property 'hasOwnProperty' of null
While I really appreciate your incredible work on this, I must admit that I find the documentation rather frustrating, as there doesn’t seem to be a “hello world” illustration of how to use a PlayerContextProvider
/ PlayerContextConsumer
.
Best, rex
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 1
- Comments: 22 (13 by maintainers)
@benwiley4000 👍for the quickstart documentation, you absolutely nailed it which suggests to me that you clearly understood why it was needed. 💯
FYI, I have made great use of
cassette
on my personal website, including use of theContextProvider
to interact with a persistent player from within page elements.desktop only
https://www.rexmort.us/senecast
☝️ Have a look!
Again, thank you so much for your work on this. I really appreciate it.
Sure thing, Ben! Thanks again for your work - it has helped me realise my own work in a very real way.
@benwiley4000 no rush, as I’ve got it working now! I would be happy to start a conversation about the documentation with you (one of my strong suits). Do you have an active chat for this project? Or just GH issues?
Ok, I see what I was doing wrong. Both the
...mediaControls
and the...consumer
must be peer child elements of the same...provider
.This is unlike the standard pattern for react context providers, I believe?
In any case, I’ve got the bastard working now, and boy does it feel good!