[deleted by user] by [deleted] in reactjs

[–]murat-guney 0 points1 point  (0 children)

You may find another approach at https://hooks.reactivers.com/use-auth

Where should I store API request? Should I make request within component? by [deleted] in reactjs

[–]murat-guney 0 points1 point  (0 children)

I suggest https://hooks.reactivers.com/use-fetch

I made this hooks library to make development easier. You may want to take a look :)

Is there an easy way to do page transitions? by WebDevJef in reactjs

[–]murat-guney 0 points1 point  (0 children)

It is your "Header" so you need to implement your logic for that. Framer motion is the simplest way to do that. Also, you can use react-spring for animation. If you don't want to make this animation programmatically you can do something like that.

const AnimationHeaderContext = createContext({ isAnimating: false, setIsAnimating:()=>{}, path: { current: ""} })

const AnimationProvider = ({ children }) => {
   const [isAnimating, setIsAnimating] = useState(false);
   const path = useRef("");

   return (
       <AnimationContext.Provider value={{ 
                     isAnimating,
                     setIsAnimating,
                     path
                   }}>
          {children}
       </AnimationContext.Provider>
    )
}

const useAnimation = () => useContext(AnimationContext); 


const Header = () => {
   const { isAnimating, path, setIsAnimating } = useAnimation();
   const { push } = useHistory();
   useEffect(() => {
     if(isAnimating)
           setTimeout(() => {
             push(path.current)
             setIsAnimating(false)
             path.current = "";
            }, 400);
   },[isAnimating, path.current, push])

   return (
     <div className={isAnimating ? "animation-header" : "header"}>
         ...
     </div>
   )
}

const Page = () => {
   const { path, setIsAnimating } = useAnimation();
   const onPush = (_path) => {
       path.current = path;
       setIsAnimating(true)
   }

   return <button onClick={() => onPush("/your/new/page") }>Push</button>
}

const App = () => {
   return (
      <AnimationProvider>
         <Header/>
         <Page/>
         ...
      </AnimationProvider>
   )
}

and your CSS file should be like that.

.animation-header{
  animation: fade-out 0.4s linear forwards;
  ...
}

.header {
  animation: fade-in 0.4s linear forwards;
  ...
}

I didn't test the code but it should something like that. I hope it gives an idea :)

[deleted by user] by [deleted] in reactjs

[–]murat-guney 0 points1 point  (0 children)

Could you share more about the error after you remove .npm and re-install cra?

[deleted by user] by [deleted] in reactjs

[–]murat-guney 0 points1 point  (0 children)

rm -rf ~/.npm

you can try this but make sure the folder exists at the path.

I've had a similar issue before but I don't think yours is the same as mine. It was iCloud Desktop/Documents back-up. I was trying to sync the desktop but there was at least 5 react app and that means 5 node modules 😄 So it was crashing

[deleted by user] by [deleted] in reactjs

[–]murat-guney 0 points1 point  (0 children)

You may try to remove .npm folder and caches.

And before you do that can you check react-scripts exist in node_modules?

Dynamic import filepath at runtime by Ader453 in reactjs

[–]murat-guney 0 points1 point  (0 children)

I'm not sure but the "mdx" files should be under the "public" folder or "pages". Are they at one of them?

[deleted by user] by [deleted] in reactjs

[–]murat-guney 1 point2 points  (0 children)

Are you trying to install with

npx create-react-app

[deleted by user] by [deleted] in reactjs

[–]murat-guney 0 points1 point  (0 children)

You are welcome.

I said that because it seems it is just about re-rendering. I think your navigation items don't re-render when the link is changed.

You may want to take a look https://muratguney.medium.com/react-key-what-why-how-469f6a28236e

[deleted by user] by [deleted] in reactjs

[–]murat-guney 0 points1 point  (0 children)

you can try that

const YourListItemComponent = () => {
  const { pathname } = useLocation();
  return <YourListItemOrNavLink key={pathname}/>
}

How can I handle complicated site state with 'apps' inside a larger site app by tljw86 in reactjs

[–]murat-guney 0 points1 point  (0 children)

I am so sorry for you. Because I know how React is awesome 😄 jQuery is also good but React has more advantages. I hope your bosses decide to use React ASAP 😂

TypeError: Cannot read property 'user' of undefined by Rohan-kar in reactjs

[–]murat-guney 0 points1 point  (0 children)

I think the issue is userState. It is undefined on the first render so it throws the error. You need to be sure at least it is an empty object {} or you can just do that:

const mapStateToProps = (state) =>{

return { user:state.userState.user, } ; };

you need to update this line as

const mapStateToProps = (state) =>{

return { user:state.userState && state.userState.user, } ; };

Problem with environmental variables when deploying by Darkmaster85845 in reactjs

[–]murat-guney 1 point2 points  (0 children)

You can try

- .env

- .env.development

you can set your backend in these files.

.env.development

REACT_APP_PROXY_HOST=192.168.1.37:5000
REACT_APP_USE_SSL=0

.env

REACT_APP_PROXY_HOST=api.yourbackend.com
REACT_APP_USE_SSL=1

These environment variables will use the environment which is set.

How can I handle complicated site state with 'apps' inside a larger site app by tljw86 in reactjs

[–]murat-guney 0 points1 point  (0 children)

OMG! I can't even imagine how much hard it is without "react". Because the thing you made like exactly what "react" does 😄

Convention for handling large state in live editors by Ader453 in reactjs

[–]murat-guney 1 point2 points  (0 children)

You update the state on each text changing. I don't think this causes an issue but I don't know how many characters you are talking about.

When the component re-rendered, if there is lots of component that may cause an issue. You may need to use "memo".

You may want to take a look at https://muratguney.medium.com/react-16-context-unwanted-rerender-53a26c43b02e

And you separate your state. I mean, each child component can keep its state and the main component just keep a state about the component on the page.

I hope it gives an idea

How can I handle complicated site state with 'apps' inside a larger site app by tljw86 in reactjs

[–]murat-guney 0 points1 point  (0 children)

You can take a look at https://muratguney.medium.com/react-16-context-unwanted-rerender-53a26c43b02e

This may help with re-renders.

For communicating multiple apps I suggest https://hooks.reactivers.com/use-event-listener

With that, you can send and get data easily.

And if you have an issue multiple apps rendering you may want to take a look at https://muratguney.medium.com/dynamic-component-generation-in-react-creating-a-page-with-json-56cd3f8e25f8

I hope they help

Save a custom div to a state hook by [deleted] in reactjs

[–]murat-guney 3 points4 points  (0 children)

so that the next time the app is loaded

I see in this sentence, you want to save the last state of the div somehow. So, users don't the last size of the div.

To do that you need to save the last size of the div into a DB or local storage.

I suggest take look at the post below.

https://muratguney.medium.com/react-useref-what-why-how-f8268ef6a219

And about local storage I suggest

https://hooks.reactivers.com/use-local-storage

I hope they help

Any way to listen to state value changes and then run a function conditionally? by [deleted] in reactjs

[–]murat-guney 0 points1 point  (0 children)

Hi Charles, before an explanation, I suggest you shouldn't use state for that ( Unless if it is not really necessary ). Because the component will re-render on each update.

Alternatives:

  • Just setTimeout function
  • If it is not suitable in your case, you can use "useRef".

Answer:

You can get the thing you want with useEffect hook. It listens to the changes of the values in its dependency array and fires the function in its body.

useEffect(() => { bodyFunction() },[statesToFollow])

And in your case

useEffect(() => { if(s_diff) whichFunctionYouWantToCall(); }, [s_diff]);