I am a new in react js, my problem is I want to create a class which will work as global helper which I want to utilzed in another class or component.
Use case for e.g First I want to fetch all resturant list keyword entered by user if user select any resturant then I want to get resturant details. in this use case I have to make two ajax call I want to create global ajax helper function which I can use in other components.
class AjaxHelperClass{
ResturantAPI(url){
$.ajax({
url : url,
success : function(res){}
});
}
}
export default AjaxHelperClass;
in my another component that use from my AjaxHelperClass function :
import React from 'react';
import {render} from 'react-dom';
import {AjaxHelperClass} from "./module/AjaxHelperClass"
class App extends React.Component {
constructor(props) {
super(props);
/// AjaxHelperClass.ResturantAPI(); // or
let myajaxresult= new AjaxHelperClass(url);
}
render () {
return(
<p> Hello React!</p>
);
}
}
render(<App/>, document.getElementById('app'));