Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access a child within LoadableComponent and Route?

In my main component, I have created a ref :

this.transfernewRef = React.createRef();

And assigned it to my component, which is embedded in a Route :

<Route path="/new" render={(props) => <TransferNew {...props} origin={this.state.origin} token={this.state.token} ref={this.transfernewRef} />}/>

My component, TransferNew, is also dynamically loaded using react-loadable and its Loadable component. If I print this.transfernewRef.current, I get a LoadableComponent object :

enter image description here

How do I access my component TransferNew from there ? I can't seem to find a proper way to do it. I'd just like to call one of TransferNew's function, so something along those lines :

this.transfernewRef.current.<something>.myFunction()

Thank you.

like image 594
Chuck Avatar asked Jun 04 '18 09:06

Chuck


1 Answers

I have the same issue. My solution

import Loadable from "react-loadable";
import { Loading } from "components/Loading";

const Dropzone = Loadable({
  loader: () => import("view/components/knowledge/components/Dropzone.jsx"),
  loading: Loading,
  render(loaded, props) {
    const Component = loaded.default;
    const ref = props.DropzoneRef || undefined;
    return <Component {...props} ref={ref} />;
  },
});
like image 96
Ilya Dvoeglazov STEELMANRUS Avatar answered Sep 30 '22 20:09

Ilya Dvoeglazov STEELMANRUS