小编aks*_*hay的帖子

无法在反应中继中获取列表

我遵循与此处提到的相同的架构

我想获取所有用户,所以我更新了这样的架构

var Root = new GraphQLObjectType({
  name: 'Root',
  fields: () => ({
    user: {
      type: userType,
      resolve: (rootValue, _) => {
        return getUser(rootValue)
      }
    },
    post: {
      type: postType,
      args: {
         ...connectionArgs,
          postID: {type: GraphQLString}
        },
      resolve: (rootValue, args) => {
       return getPost(args.postID).then(function(data){
        return data[0];
       }).then(null,function(err){
        return err;
       });
      }
    },

    users:{
      type: new GraphQLList(userType),
      resolve: (root) =>getUsers(),
    },
  })
});
Run Code Online (Sandbox Code Playgroud)

在database.js中

export function getUsers(params) {
  console.log("getUsers",params)
  return new Promise((resolve, reject) => {
      User.find({}).exec({}, function(err, users) { …
Run Code Online (Sandbox Code Playgroud)

relay node.js reactjs

4
推荐指数
1
解决办法
673
查看次数

Set dynamic key in state via useState React hooks

I want to set dynamic state with dynamic key by uuid in it in functional component Below is example with the class based Component in React

class App extends Component {
  state = {
    [uuid()]: []
  };
Run Code Online (Sandbox Code Playgroud)

How can achieve this with functional component ?

const App = props=>{
 const [list, setList] = useState([uuid()]);
Run Code Online (Sandbox Code Playgroud)

I tried using above approach it gives me output

["4b4c8872-0c35-49a6-a98b-ef7abcb2cef8"]

but desired is ["4b4c8872-0c35-49a6-a98b-ef7abcb2cef8": []]

Thanks in Advance!

reactjs

2
推荐指数
1
解决办法
891
查看次数

标签 统计

reactjs ×2

node.js ×1

relay ×1