OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Expo React, use hook from outside a export default func app

  • Thread starter Thread starter Sheee
  • Start date Start date
S

Sheee

Guest
I need assistance with expo and react Hooks

I need to manipulate the hook display (profil.tsx) from outside an app export. From the last file login.js from a regular JS function.

Is there a way I can do this or do I need to restructure the code ??

Thanks a lot for your answers, if you need further pieces of information to understand the problem don't hesitate to write what you need thanks a lot! Paul

Code:
        //profil.tsx
import { ProfileProvider, useProfile } from '../../components/profileContext';

    import abmelden from '../../components/login'
        
        
        export default function App() {
        
            const { display, setDisplay } = useProfile();//besonderer Hook...
        
        
          ...
        
        return (
        
        VIEW
        
        );}

Next file

Code:
//profileContext.js

import React, { createContext, useContext, useState } from 'react';

const ProfileContext = createContext();

export const useProfile = () => {
  return useContext(ProfileContext);
};

export const ProfileProvider = ({ children }) => {
  const [display, setDisplay] = useState('login');

  return (
    <ProfileContext.Provider value={{ display, setDisplay }}>
      {children}
    </ProfileContext.Provider>
  );
};

Next File

Code:
//login.js


export default async function abmelden(showMSG = true){

    LOGOUT PROCESS... 
    
    Here I want to acces setDisplay to change the behavior of the Screen in profile.tsx
  
  }
<p>I need assistance with expo and react Hooks</p>
<p>I need to manipulate the hook display (profil.tsx) from outside an app export. From the last file login.js from a regular JS function.</p>
<p>Is there a way I can do this or do I need to restructure the code ??</p>
<p>Thanks a lot for your answers,
if you need further pieces of information to understand the problem don't hesitate to write what you need
thanks a lot!
Paul</p>
<pre><code> //profil.tsx
import { ProfileProvider, useProfile } from '../../components/profileContext';

import abmelden from '../../components/login'


export default function App() {

const { display, setDisplay } = useProfile();//besonderer Hook...


...

return (

VIEW

);}
</code></pre>
<p>Next file</p>
<pre><code>//profileContext.js

import React, { createContext, useContext, useState } from 'react';

const ProfileContext = createContext();

export const useProfile = () => {
return useContext(ProfileContext);
};

export const ProfileProvider = ({ children }) => {
const [display, setDisplay] = useState('login');

return (
<ProfileContext.Provider value={{ display, setDisplay }}>
{children}
</ProfileContext.Provider>
);
};
</code></pre>
<p>Next File</p>
<pre><code>//login.js


export default async function abmelden(showMSG = true){

LOGOUT PROCESS...

Here I want to acces setDisplay to change the behavior of the Screen in profile.tsx

}
</code></pre>
Continue reading...
 

Latest posts

Top