use-context

dispatch is not accessible from useContext

橙三吉。 提交于 2021-01-28 08:23:28
问题 i have simple store import React, { createContext, useReducer } from "react"; import Reducer from "./UserReducer"; const initialState = { user: {}, error: null }; const Store = ({ children }) => { const [state, dispatch] = useReducer(Reducer, initialState); return ( <Context.Provider value={[state, dispatch]}> {children} </Context.Provider> ); }; export const Context = createContext(initialState); export default Store; i have wrapped my app with it like <Store> <ThemeProvider theme={Theme}>

React: useContext value is not updated in the nested function

不羁岁月 提交于 2021-01-27 07:49:06
问题 I have a simple context that sets some value that it get from backend, pseudo code: export const FooContext = createContext(); export function Foo(props) { const [value, setValue] = useState(null); useEffect(() => { axios.get('/api/get-value').then((res) => { const data = res.data; setValue(data); }); }, []); return ( <FooContext.Provider value={[value]}> {props.children} </FooContext.Provider> ); } function App() { return ( <div className="App"> <Foo> <SomeView /> </Foo> </div> ); } function

React: useContext value is not updated in the nested function

假装没事ソ 提交于 2021-01-27 07:42:41
问题 I have a simple context that sets some value that it get from backend, pseudo code: export const FooContext = createContext(); export function Foo(props) { const [value, setValue] = useState(null); useEffect(() => { axios.get('/api/get-value').then((res) => { const data = res.data; setValue(data); }); }, []); return ( <FooContext.Provider value={[value]}> {props.children} </FooContext.Provider> ); } function App() { return ( <div className="App"> <Foo> <SomeView /> </Foo> </div> ); } function

How do we handle image with filepath and convert to base64 in react hooks

牧云@^-^@ 提交于 2020-06-29 03:22:25
问题 How do we handle and convert into base64, if we receive image with path in React Hook in following format: images\photo-1592376542020.JPG UserLoginProvider.js import { UserProfileContext, UserLoginContext } from '../context'; const UserLoginProvider = ({children}) => { const [loginPhoto, setLoginPhoto] = useState({ photo:''}); const value = useMemo(() => ({ loginPhoto, setLoginPhoto }), [loginPhoto]); return ( <UserLoginContext.Provider value={value}> {children} </UserLoginContext.Provider> )

How do we handle image with filepath and convert to base64 in react hooks

假如想象 提交于 2020-06-29 03:22:23
问题 How do we handle and convert into base64, if we receive image with path in React Hook in following format: images\photo-1592376542020.JPG UserLoginProvider.js import { UserProfileContext, UserLoginContext } from '../context'; const UserLoginProvider = ({children}) => { const [loginPhoto, setLoginPhoto] = useState({ photo:''}); const value = useMemo(() => ({ loginPhoto, setLoginPhoto }), [loginPhoto]); return ( <UserLoginContext.Provider value={value}> {children} </UserLoginContext.Provider> )