I have a parent - Planner, and two children - Calendar and Week.
I want to display an element from Calendar to Week. I already can access the element in Planner using refs, but I am not sure how to forward the ref from Planner to Week.
import React from 'react';
import Calendar from './Calendar';
import Week from './Week';
const {connect} = require('react-redux');
class Planner extends React.Component {
constructor(props) {
super(props);
this.childRef = React.createRef();
}
componentDidMount() {
this.weekRef = this.childRef.current;
}
render() {
return (
<div>
<Calendar ref={this.childRef}/>
<Week ref={this.weekRef}/>;
</div>
);
}
}
const Container = connect()(Planner);
export default Container;
so i can get the necessary refs from Calendar to Planner in this.childRef
but I want to forward/pass it onto Week component to use it.
import React from 'react';
import { withRouter } from 'react-router-dom';
class Week extends React.Component {
constructor(props) {
super(props);
}
componentDidMount() {
console.log('week ref', this.props);
}
render() {
return (
<div className="Week">
Week!
</div>
)
}
}
export default React.forwardRef((props,ref) => <Week {...props} ref={ref} />);
not really sure what i am doing. any help is greatly appreciated.