0
码是这样的:如何在反应componentDidMount中设置状态与方法?
componentDidMount() {
this.setState(({getPublicTodosLength}, props) => ({
getPublicTodosLength:() => this.getPublicTodosLengthForPagination() // no returned value
}));
}
getPublicTodosLengthForPagination = async() => { // get publicTodos length since we cannot get it declared on createPaginationContainer
const getPublicTodosLengthQueryText = `
query TodoListHomeQuery {# filename+Query
viewer {
publicTodos {
edges {
node {
id
}
}
}
}
}`
const getPublicTodosLengthQuery = { text: getPublicTodosLengthQueryText }
const result = await this.props.relay.environment._network.fetch(getPublicTodosLengthQuery, {})
return result.data.viewer.publicTodos.edges.length;
}
getPublicTodosLengthForPagination不被调用和返回值不是assigned.Also,当我调用它马上例如无()=>它的赋值是一个承诺?我期待int/number,edge.length的返回值。帮帮我?
控制台中的任何错误? – stybl
@stybl没有错误,当我立即调用它时,例如without()=>它被分配给一个承诺? –