N
N
Neuro2019-07-08 17:22:28
React
Neuro, 2019-07-08 17:22:28

How to rewrite react mixins in React es6?

Good afternoon, I'm trying to migrate a project from React es5 to React es6, and I ran into a problem, namely mixins.
I have a component like this

var BasicProfileComponent = React.createClass({

    mixins: [GoogleMapApi],

    componentWillMount: function() {
        this.initializeGoogleMapApi(this.onGoogleApiLoaded);
    }
)}

and mixin to it
var GoogleMapApi = {
  initializeGoogleMapApi: function(callback) {
    if (window.apiLoaded) {
      callback();
    }

    // adding calback to a queue
    this.pullOfCallbacks.push(callback);
  }
}

How can I rewrite this component to React.Component and use mixins inside it, or how can I make an alternative record of this mixin?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Spirin, 2019-07-09
@rockon404

Too little data. Here, an option may be suitable both with transferring logic to component methods, and using HOC or Hooks API.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question