React version:
16.8.6
Steps To Reproduce
import AUserList from '../AUserList';
class AUsers extends Component {
constructor(props) {
super(props);
this.list = React.createRef();
this.divTag = React.createRef();
}
handleChangeDataList = () => {
console.log(this.list.current);//null
console.log(this.divTag.current);//it works
this.list.current.reloadAUserTable();//it is error
}
render() {
return (
<>
<div className="animated fadeIn" ref={this.divTag}/>
<AUserList ref={ref => this.list=ref}/>
<Button onClick={() => this.handleChangeDataList()}>atest</Button>
</>
)
}
}
export default connect(mapStateToProps, mapDispatchToProps, null, {forwardRef : true})(AUsers);
class AUserList extends Component {
//from AUsers
reloadAUserTable = () => {
console.log('good');
}
render() {
const {
AUserData_arr,
} = this.props;
return (
<div>
<Card>
<CardBody>
{AUserData_arr &&
<BootstrapTable data={AUserData_arr} version="4" striped hover pagination search tabIndexCell >
<TableHeaderColumn dataField="UserLevel_Name" dataFormat={this.userLevelFormatter} dataSort>LEVEL</TableHeaderColumn>
</BootstrapTable>
}
</CardBody>
</Card>
</div>
);
}
Top comments (3)
Hi Michael.
Is this a question? a post or a #devjournal?
Hi, Sung M.
Thanks for your reply.
Yes, it is a question,
To be honest I am a beginner.
So If you can guide for me, it will be great pleasure.
The callback refs is what you've used to get the
AUserList
's ref.In that case you don't access the ref with
.current
likethis.list.current
but asthis.list
.You also don't create
this.list
withReact.createRef()
with callback ref.Can you provide a minimal runnable sample with CodeSandbox.io or Stackblitz if it still doesn't work?