inviariant是react的shared/invariant包中的一个方法,它是对某个错误条件下的一个错误提醒,因为react很多地方使用,Facebook团队把它单独抽取出来写了,看看这个类的源代码,其实有很多地方值得我们去学习的,先贴出它的源代码,咱们在细细说来。
export default function invariant(condition, format, a, b, c, d, e, f) {
validateFormat(format);
if (!condition) {
let error;
if (format === undefined) {
error = new