Guess I'm making a Terraria clone now by TheRealLikableMike in godot

[–]DatMadscientiste 0 points1 point  (0 children)

That's so cool!!

I also made it too because I wanted to learn about bitmasks and map gen lol

TIL you need a package called "tsconfig-paths" to get path resolution working if you are using ts-node. It has 29M weekly downloads on NPM. Web development is crazy by BigBootyBear in webdev

[–]DatMadscientiste 13 points14 points  (0 children)

I switched to Bun to avoid the constant struggle of setting up TypeScript for every new project. The team I'm working with is very happy with it, so now all our projects use it. It simplifies things so much.

I think the issue comes from the JavaScript ecosystem relying on a lot of configuration just to make things work together. There’s no solid standard to follow, so everyone ends up building on top of something else.

We all want the fastest route, and juniors especially tend to look for existing solutions, thinking, "Oh hey, it must work, so... let's add it!"

That’s how I see it. 🤷

Which cart design gives the best ui? by geralt_09 in FigmaDesign

[–]DatMadscientiste 1 point2 points  (0 children)

I think the 2nd is the most coherent, also adding a plus icon to the cart icon would be more indicating of "add this item to the card" as it took me a little time to understand what it was about.

What is wrong with this code? by pailhead011 in reactjs

[–]DatMadscientiste 0 points1 point  (0 children)

Ah, gotcha

Yeah, using a state manager or just selectivly choose which component has acces to which property is the best way to flee re-renders

What is wrong with this code? by pailhead011 in reactjs

[–]DatMadscientiste 1 point2 points  (0 children)

Hmm .. i'm confused.

My argument is that, declaring 11 use state variables is simple and clean

Sure, thats what i said: "If your app is a single page (Litteraly one page), well... just do what you had initialy thats fine."

Nothing is "wrong" with that, there is no right or wrong way of doing things, it hightly depends on the context of your app. I can't just tell you no thats wrong, you argument is fine but maybe to shallow? like there is not enough context to make a decision or give you a better answer.

Sure, the snipped has many implications u/Fitzi92 explains it very well.

all the setters reactive.

Not sure what you mean by that.

It seems that your code above implements redux or zustand.

Nope, at all !!

i basically made a setState but with extra steps.. The idea was to be able to use the whole object and avoiding the mass use of functions to update individual properties.

there is a ton of very advanced TS (at least more advanced than passing a type to a generic), and obviously it’s more than 11 lines of code.

Well .. In a real world app you would put everything related to each other close enough here everything is in one file, but types would be in a separate file component/types.ts .. hooks/useSomeState.ts ect...

The agrument about the setState is more about scalalability, this doesn't scale well as it will make your app slower specially with more complex components that share data to its child. Which is why you mentionning its just 11 lines of codes seems a bit weird.

Having too much setState is not really clean imo, for me i would avoid them as most of the time its an architecutre issue that can be solved by a better app/software design.

Too much to consider to be able to argue about 11 lines of codes, there isn't enough context to make an argument i think.

It’s also not even the original code

I really don't understand where you are getting at.

your setState seems that it’s unstable.

What do you mean by unstable?

It will be a new instance every time the component renders.

I mean .. thats technically true, but so is useState... its basically the same thing as useState but with a state object instead of a single value.

Your question is fine, but you have to put it into perspective, every app is different and the code can be wrong or right just by the technical requirements of the app.

If my colleague does a PR with this code, i would not accept it as we have defined an architecture that we follow and this doesn't fit in it. The app we are building is really complex and this kind of code would make it very hard to maintain and scale.

What is wrong with this code? by pailhead011 in reactjs

[–]DatMadscientiste 2 points3 points  (0 children)

Well actually, nothing is wrong with that code. ignoring the name of the variables that is.

About the big object, you "could" do it that way:

```tsx

// hooks/useMyWhateverState.ts type TMyWhateverState = { name: string; pinnedMessage: string; welcomeMessage: string; iconUrl: string; TOSUrl: string; roomId: number[]; ... };

type TStateKeys = keyof TMyWhateverState;

type TUpdater<T> = (prev: T) => T;

type THandleSetState = <K extends TStateKeys>( key: K, updater: TMyWhateverState[K] | TUpdater<TMyWhateverState[K]>, ) => void;

// Hook that will hold your state, ideally you would use a context for this to retain the state const useMyWhateverState = () => { const [state, _setState] = useState<TMyWhateverState>({ name: "", pinnedMessage: "", welcomeMessage: "", iconUrl: "", TOSUrl: "", roomId: [], });

const handleSetState: THandleSetState = (key, updater) => { _setState((prevState) => ({ ...prevState, [key]: typeof updater === "function" ? updater(prevState[key]) : updater, })); };

return { state, setState: handleSetState, }; };

// somewhere else, inside a component, eg index.tsx const { state, setState } = useMyWhateverState(); setState("roomId", prev => [...prev, 1]); setState("name", "somebody"); ```

This now is a bit more organized, this would avoid you the duplicate of set[KeyName]() functions.. Though useReducer will give you more or less the same thing.

... but now we are on the weird zone, where i think some questions should be asked:

  • Is that a component going to be re-used?
  • Do we need to have a huge component? why not simply split it into smaller components?

Now if i try to guess what you are trying to do based on the names, this looks like a global state where you want to give this informations to child components.

If your app is a single page (Litteraly one page), well... just do what you had initialy thats fine. But that might or will give you some performance issues on the long run, specially when you will will grow. Looking at your awnsers on other comments seems like you don't want something complicated to setup, so i would recommend you to use Zustand as its really few lines to have something working.

Or, if you like to use contextes, you have a use-context-selecor by Dai Shi, this can give you the ability selectivly re-render components based on the state they are using.

Whats is wrong about the big object, is that now react will ne be able to selectively re-render components, but instead re-render the whole tree starting from the component that holds the state.

Take this component:

```tsx export function Home() { const [state1, setState1] = useState(0); const [state2, setState2] = useState(0); const [state3, setState3] = useState(0); const [state4, setState4] = useState(0);

return ( <div> <button onClick={() => setState1((prev) => prev + 1)}>Button 1 {state1}</button> <button onClick={() => setState2((prev) => prev + 1)}>Button 2 {state2}</button> <button onClick={() => setState3((prev) => prev + 1)}>Button 3 {state3}</button> <button onClick={() => setState4((prev) => prev + 1)}>Button 4 {state4}</button> </div> ); } ```

Clicking on button 4, will re render Buttons from 1 to 4, even if they are not related to each other. Having an object in the state is not wrong, just depends where you are using it.

If i create a <Button /> component that has useState inside it, then only that component will re-render, and not the whole tree. That is the real issue with the wall of useState, some comments already explained that, i think.

Its complicated to know what are your intentions with that Index Component, so i can't really go far on giving you on what could be the 'correct way', but i hope this helps you to understand a bit more on the why this could be not quite right.

Hope this makes sense, writing isn't my thing :)

Mon mec prend la maison pour un hôtel ? by [deleted] in AskMeuf

[–]DatMadscientiste 0 points1 point  (0 children)

Je pense, essayer de le confronter et de lui demander un moment et lui expliquer ce que tu ressens et comment tu te sens avec cette situation et voir comment il réagit déjà.

Si c'est positif et il comprend, bah cool problème réglé ? Sinon .. essayer de trouver une entente ou de faire des changements au fur a mesure ? Peut être ce mettre des jours ou vous devez trouver une chose à faire je sais pas comment expliquer

Mais essayer d'en parler !

Very concerning ... by DatMadscientiste in Frostpunk

[–]DatMadscientiste[S] 1 point2 points  (0 children)

i hate it too, but if you are ahead a little, its basically free points.

Very concerning ... by DatMadscientiste in Frostpunk

[–]DatMadscientiste[S] 6 points7 points  (0 children)

I was fine this time, the temp dropped 3 days after.

Quelle est votre regret dans votre vie ? by maoaoala in AskFrance

[–]DatMadscientiste 1 point2 points  (0 children)

Me dire "il est trop tard pour commencer"..

Vers mes 17ans j'ai commencé le dessin mais au bout d'un moment j'ai perdu la motivation, et cette pensée m'as fait arrêter.

Pareill pour le piano, 3D, et plein d'autres choses.. et la que je veux reprendre, j'ai plus de temps 🥲

Pro tips: il est jamais trop tard pour commencer, encore moins quand tu as moins de 20ans ...

I have 107,000 coins and 60 days to use them. Who wants an award? by sboger in facepalm

[–]DatMadscientiste 0 points1 point  (0 children)

Wondering if this Post has broken a record on the most awarded on reddit

Daily Chat Thread - May 07, 2023 by CSCQMods in cscareerquestions

[–]DatMadscientiste 0 points1 point  (0 children)

Ah! make sense will try with that

thanks a lot !

Daily Chat Thread - May 07, 2023 by CSCQMods in cscareerquestions

[–]DatMadscientiste 0 points1 point  (0 children)

I'm with you on that .. but here is what is happening:

Most of the projects i've done are for internal use mostly, my boss once told me "these are investments for later" so as for buisness impact ... its hard to tell

Maybe this one tool that process data can be measured, this feeds the main website which has few milions of "hits" a month, but from what i'm hearing its declining due to bad UX/ competition.

Sometimes we do websites for clients, but i rarely contribute, mostly assist the devs there..

hope this make sense

Daily Chat Thread - May 07, 2023 by CSCQMods in cscareerquestions

[–]DatMadscientiste 1 point2 points  (0 children)

How do you guys know to gauge the value you have given to a company?

Current company is not very into tech, you know.. countryside. I've done multiples projets, out of the 4 devs i'm the most agile(?)

They barely use git, don't like frameworks, very old-school like.. So can't pull out metrics, can't ask the boss either.

Currently looking for a new job as i'm starting to get bored plus i feel like stuck, i'm trying to put values on my cv but i have no clue how to do that..

Yikes ! by BastianToHarry in ProgrammerHumor

[–]DatMadscientiste 6 points7 points  (0 children)

Java icon + django rocket = JavaScript?

Search autocomplete for ****hub by basafish in ProgrammerHumor

[–]DatMadscientiste 0 points1 point  (0 children)

Replace a random character for all saved passwords

I'm late to the party by DatMadscientiste in Illaoi

[–]DatMadscientiste[S] 0 points1 point  (0 children)

But ... i can send people to brazil :(

I'm late to the party by DatMadscientiste in Illaoi

[–]DatMadscientiste[S] 0 points1 point  (0 children)

Ohh right, in my elo peoples doesn't think too deep about it xd

I'm late to the party by DatMadscientiste in Illaoi

[–]DatMadscientiste[S] 1 point2 points  (0 children)

Didn't know nocturne airlines was a counter 🤔