Call a React component method from outside

前端 未结 11 1577
灰色年华
灰色年华 2020-11-28 04:56

I want to call a method exposed by a React component from the instance of a React Element.

For example, in this jsfiddle. I want to call the alertMessage

11条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-28 04:59

    If you are in ES6 just use the "static" keyword on your method from your example would be the following: static alertMessage: function() { ...
    },

    Hope can help anyone out there :)

提交回复
热议问题