如何记录 "setState" 函数
How to document the "setState" function
问题
我正在尝试用 JSdoc. Here is the example 记录事件 我关注了:
/**
* Throw a snowball.
*
* @fires Hurl#snowball
*/
Hurl.prototype.snowball = function() {
/**
* Snowball event.
*
* @event Hurl#snowball
* @type {object}
* @property {boolean} isPacked - Indicates whether the snowball is tightly packed.
*/
this.emit('snowball', {
isPacked: this._snowball.isPacked
});
};
按照这个例子,我记录了我的事件如下。
Inside a class named "Something"
/**
Update state to include entered Thing Name
@fires Something#handleThingChange
*/
handleThingChange = (evt) => {
/**
handleThingChange event.
@event Something#handleThingChange
@type {updater}
@property {string} state.thing
*/
this.setState({ thing: evt.target.value });
}
问题
我不确定如何记录 setState 函数。是 updater? Or does it warrant the @callback 标签类型吗?
根据您的代码,我认为它将是 updater
.
类型
说明
ReactComponent.setState
"updates" 当前组件状态,因此将其记录下来是有意义的。是的,该方法有一个可选的 callback
参数,但我不会考虑它,因为您不使用它。
问题
我正在尝试用 JSdoc. Here is the example 记录事件 我关注了:
/**
* Throw a snowball.
*
* @fires Hurl#snowball
*/
Hurl.prototype.snowball = function() {
/**
* Snowball event.
*
* @event Hurl#snowball
* @type {object}
* @property {boolean} isPacked - Indicates whether the snowball is tightly packed.
*/
this.emit('snowball', {
isPacked: this._snowball.isPacked
});
};
按照这个例子,我记录了我的事件如下。
Inside a class named "Something"
/**
Update state to include entered Thing Name
@fires Something#handleThingChange
*/
handleThingChange = (evt) => {
/**
handleThingChange event.
@event Something#handleThingChange
@type {updater}
@property {string} state.thing
*/
this.setState({ thing: evt.target.value });
}
问题
我不确定如何记录 setState 函数。是 updater? Or does it warrant the @callback 标签类型吗?
根据您的代码,我认为它将是 updater
.
说明
ReactComponent.setState
"updates" 当前组件状态,因此将其记录下来是有意义的。是的,该方法有一个可选的 callback
参数,但我不会考虑它,因为您不使用它。