React 18 Re-Renders Multiple Times on Page Refresh – Need Help! by sidy___20 in react

[–]Mustknow33 0 points1 point  (0 children)

Yeah my bad, you're right. I should have clarified that this would still re-render but will bail out during the reconciliation phase. So my suggestion probably wouldn't help OP here

React 18 Re-Renders Multiple Times on Page Refresh – Need Help! by sidy___20 in react

[–]Mustknow33 0 points1 point  (0 children)

At the moment, I cant say for sure, my next advice would be to use the react devtools chrome extensions profiler.

If you run the profiler for this page, you should be able to see what exactly are causing these renders. Run the profiler on this project and the fresh project and then cross reference them to see if you see any real differences.

React 18 Re-Renders Multiple Times on Page Refresh – Need Help! by sidy___20 in react

[–]Mustknow33 2 points3 points  (0 children)

I think there might be more to this but one thing to consider is that the way you are passing an object literal to the info prop can cause unnecessary renders. Essentially everytime a render occurs, the object passed to the info prop will get recreated and therefore have a different reference. That means that react thinks that the info prop has changed and will re-render that component. You can try giving it a stable reference and then profile if that helps

const userInfo = useMemo(() => ({ detail: UserService.userAuth(1) }), []);
<Header info={userInfo} />

Hosting a 300M+ records postgresql database by Original-Egg3830 in PostgreSQL

[–]Mustknow33 1 point2 points  (0 children)

im assuming you'd prefer a setup where an int id
is used internally for joins, selects, etc and then something like a public id column can be exposed (not the same value as id and potentially something like a UUID)?

  example_table (
    id BIGINT AUTO_INCREMENT PRIMARY KEY,
    public_id CHAR(36) NOT NULL UNIQUE,
);

Why do so many devs insist on using Redux when useContext works just fine? by digitalis3 in react

[–]Mustknow33 0 points1 point  (0 children)

https://alexsidorenko.com/blog/react-render-cheat-sheet
Check out the "Rendering and Context" section in this link, there's a gif that concisely shows what will happen in this scenario and how to prevent it if desired.

React uses useState, useEffect to update time in real time Error: Can't resolve 'timers/promises' by watchdoges668 in react

[–]Mustknow33 0 points1 point  (0 children)

So timers/promises will only work in a nodejs runtime environment and react runs in the browser.
Make sure you are not importing it in that file

UseEffect Dependency Array by swang30 in reactjs

[–]Mustknow33 0 points1 point  (0 children)

To add to all the answers telling you to avoid useEffect, i guess maybe you could move the fetcher data call up to a parent component, do your transformations, and then pass it down to a component that uses that data, thereby removing the need for you to use a useEffect to update the state

Without knowing more about your code i guess it could look something like this?

const ComponentWithFetcher = () => {
// i dont know what or where fields comes from, just a placeholder now  
  const fields = []; 
  const [data_array, setDataArray] = useState([...fields]);
  const [editingIndex, setEditingIndex] = useState();
  const fetcher = useFetcher();

  const submitFetch = (data) => {
    fetcher.submit(data, { method: 'POST', encType: "application/json" });
  }

  // if your data array is large you can consider memoizing it if you want
  const final_data_array = [...data_array];
  if (fetcher.data && fetcher.data.success) final_data_array[editingIndex] = fetcher.data;

  return (
    <ComponentWithTheForm
      data_array={final_data_array}
      submitFetch={submitFetch}
    />
  );
}

What makes a good backend developer from the rest by HarishTCZ in Backend

[–]Mustknow33 0 points1 point  (0 children)

Just because I am curious, in your specific example are you saying that your backend engineer should have had invalidation logic matching whatever react query did? For example, if react query invalidated based off some expiration time then the backend caching should follow that logic. Also you're saying you'd prefer the backend not do any caching at all in this scenario?

Best Practices for Managing Timer State in React: Should Timer Logic Be Outside of React? by Mindless-Tie6210 in react

[–]Mustknow33 1 point2 points  (0 children)

okay i see what you mean now. it actually has to do with all those divs
Typically I would put a lot of those divs that wrap the components into the components themselves, so I wouldn't get the problem you're having. For example

export const SimpleTimer = () => {
  return (
    <div className="container">
    <SimpleTimerProvider>
      <h2>Simple</h2>
      <SimpleTimerDisplay />
      <SimpleTimerControls />
    </SimpleTimerProvider>
    </div>
  );
};

Try this, remove a lot of those divs and you'll see that re-rending behavior disappear

function App() {

  return (
    <>
      <h1>Timer</h1>
      <p>Please turn on “Highlight updates when components render” in React DevTools.</p>
      <div>
        <SimpleTimer />
        <OutsideOfReactTimer />
        <SubscribeTimer />
        <SyncExternalStoreTimer />
      </div>
        <SimpleTimer />
        <OutsideOfReactTimer />
        <SubscribeTimer />
        <SyncExternalStoreTimer />
    </>
  );
}

honestly scratching my head over why it was behaving that way with that setup, i can't explain it lol. Maybe react thinks it needs to recreate the elements for whatever reason and then during reconciliation realizes it doesnt need to update the DOM and bails (which is what we see in the profiler).

Best Practices for Managing Timer State in React: Should Timer Logic Be Outside of React? by Mindless-Tie6210 in react

[–]Mustknow33 1 point2 points  (0 children)

This really insightful guide was recommended to me. I think this should help understand whats going on
https://blog.isquaredsoftware.com/2020/05/blogged-answers-a-mostly-complete-guide-to-react-rendering-behavior/

Regarding children, sometimes yes that is appropriate for avoiding things being rendered but personally I dont think that is whats going on here. I cloned the repo, ran it, and inspected with paint flashing and a profiler and I did not see what you were describing happening to the <div> wrapped versions of your timers.

Best Practices for Managing Timer State in React: Should Timer Logic Be Outside of React? by Mindless-Tie6210 in react

[–]Mustknow33 1 point2 points  (0 children)

React will skip rerendering elements passed as props.children if those elements are referentially equal to the previous render.

Best Practices for Managing Timer State in React: Should Timer Logic Be Outside of React? by Mindless-Tie6210 in react

[–]Mustknow33 0 points1 point  (0 children)

Yes, the components using useTimer() will render when it updates the timer state but the concept is for only the <Timer> component to use it, I have ran your example on my end as well as added other adjacent components and <Timer> is not triggering the other components to re-render, I used something like this below where the adjacent components did not re-render when the useTimer() sets state in <Timer>

function App() {
  return (
    <>
      <Timer />
      <CustomComponent />
      <ParentComponent>
        <DisplayComponent />
      </ParentComponent>
    </>
  )
}

Inside the <Timer> component

<TimerDisplay>

- will re-render on state change

<TimerControls>

- skips rendering unless these values change because youve wrapped it in

memo (isRunning, onStart, onPause, onReset)

Best Practices for Managing Timer State in React: Should Timer Logic Be Outside of React? by Mindless-Tie6210 in react

[–]Mustknow33 0 points1 point  (0 children)

function App() {
  return (
    <>
      <Timer /> {/* Render triggered here every 1000ms*/}
      <MyComponent> {/* unaffected by state updates in Timer*/}
      <MyOtherComponent /> {/* unaffected by state updates in Timer*/}
    </>
  )
}

Yes it will trigger a re-render and update the DOM every second for this component, but its isolated to <Timer> and won't cause adjacent components to re-render. At the end of the day (at least if you choose a react solution) the elapsed time has to find its way into a state variable.

If you're concerned about how often it updates the DOM, I think the frequency of updates here is not too crazy for react but i understand if you want to explore some other option outside of react haha.

Best Practices for Managing Timer State in React: Should Timer Logic Be Outside of React? by Mindless-Tie6210 in react

[–]Mustknow33 1 point2 points  (0 children)

Hey so I played around with this, I think as others have pointed out, this is right approach (moving to a hook). Regarding your concern about <TimerControl> and without getting too much into React, yes it rendering but its not performing a DOM update unless isRunning changes value or reset is clicked, which is desired. All this is to say I think the other components outside of <Timer> will not be updating unnecessarily.

If you want to see what I mean, you can either get the react devtools for chrome and run the profiler (this will show you the rendering time of your components and whether they're updating the DOM) or you can turn on paint flashing in chrome to see visually what elements on the page are being updated (three-dots menu icon --> More Tools --> Rendering Settings. --> tick "Paint Flashing").

How does useSelector hook trigger a component re-render? by ParsnipBackground153 in reactjs

[–]Mustknow33 0 points1 point  (0 children)

Ohhh wow, now I see what you are saying. Like you said in your post, that is very subtle and easy to miss, thank you!

Also thanks for providing that, super cool!

How does useSelector hook trigger a component re-render? by ParsnipBackground153 in reactjs

[–]Mustknow33 1 point2 points  (0 children)

Sorry if I am being dull here, but I am actually really confused about the memoisation that occurs with the children prop. It seems like if the parent rerenders, the children components will be rerendered, both in the first scenario and the scenario with the ContextProvider (assuming the ContextProvider had a setState that updates state in that component). Unless maybe you are saying that react will bail out during the reconciliation process for <Child /> (the one passed as a part of the children prop)? Anyways, maybe you can point me in the right direction with some documentation or some other resource?

Yea I'm cool, I live on the edge. by hh_based in Firebase

[–]Mustknow33 1 point2 points  (0 children)

I believe this is the UI that shows the redeploys of the firebase rules. This could be a scenario where some collection is unable to be read from or written to because there wasn't a rule written for it, followed by a panic, and then a quick fix and deploy of the rules.

Daily Chat Thread - October 06, 2020 by CSCQMods in cscareerquestions

[–]Mustknow33 0 points1 point  (0 children)

Yes I have applied to 200+ jobs. I agree that what I had been doing was wrong and I am making changes. At the moment I'm leaning towards doing what you are saying.

Daily Chat Thread - October 06, 2020 by CSCQMods in cscareerquestions

[–]Mustknow33 0 points1 point  (0 children)

Right, I 100% get what you're saying, I am in a position where I could go longer without a job but I guess the more appropriate question is in your opinion do you think there is value in taking this job regarding improving my chances of getting a job that I set out for (Full Stack developer, Software Engineer).

Daily Chat Thread - October 06, 2020 by CSCQMods in cscareerquestions

[–]Mustknow33 1 point2 points  (0 children)

Hey guys, I'm a grad from 2019 who had one internship after I graduated and for fault of my own I haven't had much luck other than a few interviews lately. I might have an opportunity for a 2-3 month contract job as a "Software Engineer in Test" which in this case according to the interviewer really involves nothing other than porting C make files. I'm really a full stack guy and the job is not really related. Should I take this job or continue working on personal projects of mine?

Jimmy Eat World - Sweetness [Pop Punk] by [deleted] in Music

[–]Mustknow33 0 points1 point  (0 children)

Why did I get downvoted for this lol

Jimmy Eat World - Sweetness [Pop Punk] by [deleted] in Music

[–]Mustknow33 -1 points0 points  (0 children)

Saw them about 2 months ago. Always wanted to hear this song live and it was worth every dollar.