如何从 reactjs 中的静态方法调用另一个方法?

How to call another method from a static method in reactjs?

我刚刚转换了一些过时的事件,现在我正在使用静态的“getdirivedstatefromprops”。是否可以从此方法调用实例方法?

来自MDN documentation

The static keyword defines a static method for a class. Static methods aren't called on instances of the class. Instead, they're called on the class itself. These are often utility functions, such as functions to create or clone objects.

静态方法不需要 class 的实例存在,但是在实例化 class 之前不能调用实例方法。因此,您不能从静态方法调用实例方法。

您应该只使用静态方法来执行不需要 class 实例存在的实用程序任务。这应该告知您何时使用静态方法的决定。如果您需要 class 的一个实例,请创建一个并使用它。