【发布时间】:2020-06-19 23:42:53
【问题描述】:
我正在使用``查询:
const GET_COMMENTS = gql`
query getComments {
getComments (where: {code: "/about-us" }) {
id
text
createdAt
}
}
`
....
const { loading, error, data } = useQuery(GET_COMMENTS);
在我的代码中...
代码是从服务器中获取 cmets 的注释对象是 date: string! 属性,我想将这个 date: string! 转换为 javascript 日期 (new Date(comment.date)) 如何在获取数据后直接执行此操作?
我不想转换每次调用的渲染。
有这样的吗?:
const { loading, error, data } =
useQuery(
GET_COMMENTS,
{
transform: (data) => data.map(comment => ({...comment , date: new Date(comment.date)}) )
}
);
感谢您的帮助!
【问题讨论】:
标签: graphql react-hooks react-apollo