對於多個React組件,我想在React的生命週期中注入一個通用代碼。
有什麼好方法嗎?如何在組件中注入通用代碼React
var ComponentA = React.createClass({
componentWillMount: function() {
},
componentDidUpdate: function(){
//inject common code
},...
var ComponentB = React.createClass({
componentWillMount: function() {
},
componentDidUpdate: function(){
//inject common code
},...
事實上,它沒有工作的@jzm方法,我也在mixin中解決。 mixin看起來很有用。 – izuchy
對不起,你是什麼意思'我在mixin中也解決了? –
@izuchy將來不會支持Mixins的反應。所以他們不是解決這個問題的正確方法。 https://facebook.github.io/react/blog/2016/07/13/mixins-considered-harmful.html – jzm