【发布时间】:2019-10-05 20:59:23
【问题描述】:
我有来自 react-apollo-hooks 的 useQuery 和 useMutation 背靠背。我希望能够将 useQuery 的返回值用作 useMutation 的变量。目前,useQuery 的值没有及时返回给变量,导致变量未定义。
const { data, error, loading } = useQuery(GET_POSTS, {
variables: {
id: props.match.params.id
}
})
const item = props.match.params.id
const owner = data.posts[0].author.id
const variables = { item , owner, startDate, endDate }
const bookItem = useMutation(CREATE_BOOKING_MUTATION, variables)
变量data.posts[0].author.id 显示未定义。如何确保返回的值是及时定义的?
【问题讨论】:
-
如果您可以从后端查询该数据,您是否已经拥有该数据可在解析器中用于突变?
标签: javascript reactjs graphql react-apollo react-hooks