我有下面的代码,问题在于我在映射函数中调用RemoveProduct函数的部分:
function AddOrder() {
const d = new Date();
let text = d.toString();
const [addOrder] = useMutation(queries.ADD_ORDER);
const [editUser] = useMutation(queries.EDIT_USER_CART);
const [editProduct] = useMutation(queries.EDIT_PRODUCT);
f
,正如它在标题中所说的,我似乎不能使用钩子
我知道你们中的一些人会试图告诉我这是一个副本,但在我所见过的所有问题中,似乎没有人会问,使用导入的功能组件(我试图呈现的组件)的正确方式是什么。
import React from 'react';
import { hot } from 'react-hot-loader';
import Playground from '../playground/index';
class App extends React.Component {
render() {
Playground
您好,我正在尝试创建一个函数,当您单击产品页面上的添加到购物车时调用该函数。此函数位于一个单独的文件中,并被导入到产品页面中,名为onClick。但是,我收到这个错误,指出钩子调用无效。我做错了什么?
import {AuthContext} from '../context/auth'
import gql from 'graphql-tag'
import {Button} from 'semantic-ui-react'
import {useMutation} from '@apollo/react-hooks'
con
错误:
React Hook "useState" is called in function "createFlight" that is
neither a React function component nor a custom React Hook function.
React component names must start with an uppercase letter react-
hooks/rules-of-hooks
我的代码:
import React, {Component} from 'react'
似乎如果你不将Material-UI样式表注入到jest/react-testing-library测试中,那么jsdom将无法从你的组件中获得正确的样式(例如,运行getComputedStyle(component)将为组件返回不正确的样式)。
如何正确设置jest/react- test -library测试,以便将样式正确地注入到测试中?我已经将组件包装在一个主题提供程序中,可以很好地工作。
在我的多次尝试中,我尝试使用react-apollo-hooks和formik一起使用,但似乎不太可能。表单中的数据仅在<Formik>标记中可用,否则无法在其外部访问。此外,我不能同时调用我的useMutation钩子并将参数传递给它:
const SignUp = () => {
const classes = useStyles();
// The react-apollo-hook for useMutation
// Its not hard to call this, but it seems impossible to call it,
// w
我们正在开始一个新的反应项目使用CRA。并且,正在计划使用React查询。
需要项目文件夹结构的帮助。基于功能的文件夹结构与基于文件类型的结构有什么优势?
另外,只使用axios/fetch调用并在组件中直接创建useQuery/useMutation钩子的service/API有什么好处?为每个reactQuery创建自定义钩子?
// API call in a service file and using that API call in the component
export const fetchPost = (key, postId) =>
axios.get(`/ap
我将一个用户添加到一个api中,它带有react query的useMutation钩子。它起作用了。现在,我需要将新用户添加到处于我状态的用户数组中。
我知道我应该用useQuery查询所有用户,然后在useMutation中使用onSuccess修改缓存。但是在某些情况下,我不使用useQuery来获取用户,所以我需要像正常的承诺那样更新本地状态。
目前,我只需检查支柱“成功”是否为真,如果是的话,我将更新数组。但它只适用于第二次点击。为什么以及如何解决这个问题?
onAddUser()内部的成功条件似乎只有在第二次单击时才能达到。
export default function Ap
我有一个自定义钩子,它使用react-router-dom的useNavigate钩子。我只想添加一个测试,用于检查是否将期望值传递给了钩子。钩子只是在URL中存储和检索查询参数的值。 这是我的自定义钩子的样子- import { useState } from 'react';
import { useNavigate } from 'react-router-dom';
import { useSearchParam } from 'react-use';
// Default value for the tokens
export co