我很难在上下文提供者中设置引用。这是不可能的,还是我想念什么?我能够以相同的方式在其他组件中创建Ref,但是以下内容始终将ref显示为{current:null}
# read entire file
read buffer length: 8192
read buffer length: 8192
read buffer length: 8192
read buffer length: 8192
read buffer length: 8192
output length: 20000
# read part of file file
read buffer length: 10000
output length: 10000
# read beyond end of file file
read buffer length: 30000
read buffer length: 10000
output length: 20000
然后我的应用就这样包裹了
const VideoPlayerContext = React.createContext();
export default class VideoPlayerProvider extends Component {
videoPlayerComponent = React.createRef()
state = {
// some state
}
seek = (time) => {
this.videoPlayerComponent.seek(time)
}
render () {
return (
<VideoPlayerContext.Provider value={Object.assign({}, this.state, { seek: seek})}>
<VideoPlayer
key={'videoplayer'}
{...this.state}
ref={this.videoPlayerComponent}
/>
{ this.props.children }
</VideoPlayerContext.Provider>
)
}
}
任何帮助表示赞赏!