我遵循与此处提到的相同的架构
我想获取所有用户,所以我更新了这样的架构
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) 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!