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()=>它被分配給一個承諾? –