我正在尝试创建一个带有状态的钩子,并将其用作多个组件的公共源。
我试过什么
import React, {useState} from 'react';
/**
* Example of Hook that holds state, which should update other components when it changes
*/
const useExternalHookAsState = () => {
const [message, setMessage] = useState('nothing yet');
const
我有一个名为useIsUserSubscribed的自定义钩子,它检查是否订阅了特定的用户。如果用户被订阅,则返回true,如果用户没有订阅,则返回false .
import { useState, useEffect } from "react";
import { useSelector } from "react-redux";
import { checkSubscription } from "../services";
// this hook checks if the current user is subscribed to
我正在学习React并使用文档中新实现的“钩子”。我在使用useEffect()函数的Modal (来自Material UI的对话框)和打开/关闭函数时遇到了问题。 我已经读过这两篇文章了:React.useState does not reload state from props和How to sync props to state using React hook : setState() 它已经帮助了我,我忘记了使用useEffect()函数,而只是从道具中设置useState。了解到useState将只执行一次来设置初始状态。但是我还有一个问题。 function AddItem
我有一个名为useIsUserSubscribed的自定义钩子,它检查是否订阅了特定的用户。如果用户被订阅,则返回true,如果用户没有订阅,则返回false .
import { useState, useEffect } from "react";
import { useSelector } from "react-redux";
import { checkSubscription } from "../services";
// this hook checks if the current user is subscribed to