Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
worms butthole guy
Jan 29, 2021

by Fluffdaddy

Chenghiz posted:

Don't use splice (because it mutates), use filter or slice.

doesn't slice remove all elements up to x?

Adbot
ADBOT LOVES YOU

Chenghiz
Feb 14, 2007

WHITE WHALE
HOLY GRAIL
In your particular case you want filter. In general when you would use splice, use filter or slice instead

worms butthole guy
Jan 29, 2021

by Fluffdaddy
gotcha okay, thanks!

edit: although I guess my question is, can you use filter with the index of a array? that's what i'm passing through, since I theoretically can have items with the same ID #

worms butthole guy
Jan 29, 2021

by Fluffdaddy
edit; ignore me lmao

worms butthole guy fucked around with this message at 16:07 on Oct 19, 2022

prom candy
Dec 16, 2005

Only I may dance
This is not at all the question you asked but I'm gonna give you unwanted advice anyway. If these are Redux reducers you should be using Redux Toolkit. Hand-writing your reducers and actions is hell. Redux Toolkit is the officially recommended way to write Redux now and it's way better. It also has immer built in which makes dealing with immutability way easier.

https://redux-toolkit.js.org/

You don't have to adopt it all at once but I would stop writing any new new reducers pretty much immediately and start using RTK for those.

worms butthole guy
Jan 29, 2021

by Fluffdaddy
I guess my question would be what's the benefit of using Redux over handwriting them for a simple use case like this? That's not me being snarky I just kinda like hand writing them as it reminds me of video game state machines. I'm not using Redux though, just the basic functions of React (useContext)

teen phone cutie
Jun 18, 2012

last year i rewrote something awful from scratch because i hate myself

worms butthole guy posted:

edit: although I guess my question is, can you use filter with the index of a array? that's what i'm passing through, since I theoretically can have items with the same ID #

ya. filter takes a callback function that takes the index as the second argument

TypeScript code:
['hello', 'goon'].filter((eachWord, eachIndex, originalArray) => {
  if (eachIndex === 1) {
     // whatever
  }
})

teen phone cutie fucked around with this message at 17:18 on Oct 19, 2022

worms butthole guy
Jan 29, 2021

by Fluffdaddy

teen phone cutie posted:

ya. filter takes a callback function that takes the index as the second argument

TypeScript code:
['hello', 'goon'].filter(eachWord, eachIndex, originalArray => {
  if (eachIndex === 1) {
     // whatever
  }
})

genious.

prom candy
Dec 16, 2005

Only I may dance

worms butthole guy posted:

I guess my question would be what's the benefit of using Redux over handwriting them for a simple use case like this? That's not me being snarky I just kinda like hand writing them as it reminds me of video game state machines. I'm not using Redux though, just the basic functions of React (useContext)

I actually use createSlice quite a bit to create reducers for use with useReducer even though it's meant for Redux. I don't use Redux anymore really. I also wouldn't be hand rolling my own global store with useContext either though (if that's what you're doing). It has performance issues if you have a lot of components hooked up to one context.

I'm just surprised to see someone hand rolling a reducer, I haven't done that in a long time.

Sistergodiva
Jan 3, 2006

I'm like you,
I have no shame.

I think the redux browser addon makes it worth it alone. But yeah, toolkit all the way.

worms butthole guy
Jan 29, 2021

by Fluffdaddy
Question and not trying to be a troll but how is redux faster then native react functionality

Summit
Mar 6, 2004

David wanted you to have this.
If you aren’t creating a complex app do yourself a massive favor and look into jotai and zustrand. Absolutely perfect state management for simple apps.

teen phone cutie
Jun 18, 2012

last year i rewrote something awful from scratch because i hate myself

worms butthole guy posted:

Question and not trying to be a troll but how is redux faster then native react functionality

first of all, if using useReducer is working for your usecase, by all means use it you don't have to use Redux and it's no faster than using local state, unless you're pairing it with the context API.

I'd start thinking about state management libraries if you've got a lot of contexts which contain state and wrap your entire app, because in that case, every child of the context is going to re-render every time the state changes

it sounds like you're still very much learning and if this is a personal project, just do what's easiest for you

fsif
Jul 18, 2003

Yeah, and if you live the Redux devtools, you can hook your Zustand store into them.

worms butthole guy
Jan 29, 2021

by Fluffdaddy

teen phone cutie posted:

first of all, if using useReducer is working for your usecase, by all means use it you don't have to use Redux and it's no faster than using local state, unless you're pairing it with the context API.

I'd start thinking about state management libraries if you've got a lot of contexts which contain state and wrap your entire app, because in that case, every child of the context is going to re-render every time the state changes

it sounds like you're still very much learning and if this is a personal project, just do what's easiest for you

Nah, not neccesarily learning, my job just has me make proof of concepts in several languages and this one poc involved a bunch of moving parts dependant on others in React. Totally interested in looking into state management's if it makes proofs easier to make and faster, I was just confused why a non React library would be faster than React itself.

My state management uses the useReducer hook. This for example is what I used for a personal project which is similar to what I used for this proof:

worms butthole guy
Jan 29, 2021

by Fluffdaddy
Oh also I forgot to say that the system we work in only allows a total package size of 1mb before webpack lol.so it's usually a question of "is this package worth the space"

barkbell
Apr 14, 2006

woof
dont use redux its bad

prom candy
Dec 16, 2005

Only I may dance
Context's performance issues are because you can't subscribe to just part of your context. So say you have a context that provides an object with cats and dogs. If you have a component subscribed to it that only cares about cats it will still re-render even if dogs changes. Redux and other state management tools use techniques for subscription that will only cause re-renders if the specific slice of state you care about changes.

There is some new poo poo in react 18 that I think improves the context situation but really if you have a bunch of global state id look at Zustand and Jotai and use the one that feels right to do. Personally I like Zustand.

Also if you're mainly just syncing server state literally just use react-query. There's not even a discussion worth having about that at this point, it's by far the best data fetching and caching lib for React.

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
Took a long hiatus from Vue because I needed to make money again for a while, I'm playing around with it again. It looks like it's come a long way, I used to like it a lot and now it's really really good. At least that's my first impression.

It installed very quickly, my package.json isn't loaded with tons of garbage. It runs in it's development environment without any noticeable compilation, live updates occurring the ms I save a file. It's great.

Vuex seems to have disappeared. There's an alternative one but otherwise the docs lay out everything you might do with a complex state management system without needing one. I'm reading reports that you probably don't want to use Typescript with it which is a bit disappointing but understandable.

Looking good.

Spime Wrangler
Feb 23, 2003

Because we can.

Wrong! Use typescript.

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
I haven't written anything clientside without typescript in a while, I bet I can do it.

lunar detritus
May 6, 2009


Nolgthorn posted:

I'm reading reports that you probably don't want to use Typescript with it which is a bit disappointing but understandable.

What? Vue 3 is amazing with typescript

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
What about the state management, can I write a relatively complex spa without pinia?

Spime Wrangler
Feb 23, 2003

Because we can.

Nolgthorn posted:

I haven't written anything clientside without typescript in a while, I bet I can do it.

do you want that on the tombstone in a serif or non-serif font?

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense

Spime Wrangler posted:

do you want that on the tombstone in a serif or non-serif font?

"Tried to write a SPA without Typescript." in gothic bold.

lunar detritus
May 6, 2009


Nolgthorn posted:

What about the state management, can I write a relatively complex spa without pinia?

Pinia also supports TS with no issues, it's even written in typescript, but ...I guess, sure? I'd use provide/inject as the base, but I think it'd get very messy very fast if you're not careful.

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
I was just meaning is pinia necessary or do you recommend it.

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

prom candy posted:

Context's performance issues are because you can't subscribe to just part of your context. So say you have a context that provides an object with cats and dogs. If you have a component subscribed to it that only cares about cats it will still re-render even if dogs changes. Redux and other state management tools use techniques for subscription that will only cause re-renders if the specific slice of state you care about changes.

There is some new poo poo in react 18 that I think improves the context situation but really if you have a bunch of global state id look at Zustand and Jotai and use the one that feels right to do. Personally I like Zustand.

Also if you're mainly just syncing server state literally just use react-query. There's not even a discussion worth having about that at this point, it's by far the best data fetching and caching lib for React.

You should watch this video!


https://www.youtube.com/watch?v=ZKlXqrcBx88

prom candy
Dec 16, 2005

Only I may dance

Haha yeah that was the "there's some new poo poo in React 18 that improves this" part. I haven't watched the video yet but it's been in my YT recs for a while. I like Jack Herrington but his videos are a bit long for me so I often don't get around to watching them. Is this that useSyncExteralStore stuff or is it something else?

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense

prom candy posted:

Haha yeah that was the "there's some new poo poo in React 18 that improves this" part. I haven't watched the video yet but it's been in my YT recs for a while. I like Jack Herrington but his videos are a bit long for me so I often don't get around to watching them. Is this that useSyncExteralStore stuff or is it something else?

Yeah, apparently after learning just one more thing (useSyncExteralStore) you can eliminate 4 extra lines of code you used to have to write. The convenience is off the charts.

prom candy
Dec 16, 2005

Only I may dance

Nolgthorn posted:

Yeah, apparently after learning just one more thing (useSyncExteralStore) you can eliminate 4 extra lines of code you used to have to write. The convenience is off the charts.

It still seems like using one of the many excellent off the shelf state managers would be a better idea, no?

Cheston
Jul 17, 2012

(he's got a good thing going)
Any recommendations for senior front-end engineer interview prep? Or just Senior interview prep in general? I have no problem with the coding challenges I'm getting, and I can talk very well about personal projects, but I feel like I'm supposed to be asking five erudite questions every minute and I can't think of any.

The Fool
Oct 16, 2003


https://forums.somethingawful.com/showthread.php?threadid=3845966&perpage=40&noseen=1#post480076891

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense

prom candy posted:

It still seems like using one of the many excellent off the shelf state managers would be a better idea, no?

Sort of something that's confusing me about Vue 3 right now, reading the documentation. The built in component state management has been separated, so you can actually define a state in a separate file and import it in multiple components.

At that point it's half way to being a state manager. Makes me wonder what I need Pinia for at all, I'm sure after a bit of experimentation I'll figure it out. Maybe Vue 4 will give up on component state and state management being separate things entirely.

It'll just be one clean tree shaken dependency, where I can define little state managers and big state managers to my heart's content.

Nolgthorn fucked around with this message at 08:31 on Oct 27, 2022

hey mom its 420
May 12, 2007

prom candy posted:

It still seems like using one of the many excellent off the shelf state managers would be a better idea, no?
Pretty much, yeah. Both Zustand and Jotai are small, easy to use and just really well-designed libraries. I'm using Jotai to sync some global state on our company's new project and can attest it's very nice.

Did y'all see Next 13? It looks really good. It's like we can finally write JS like we wrote PHP, but in a good way.

worms butthole guy
Jan 29, 2021

by Fluffdaddy
So I mostly work with HubSpot and at their developer conference they announced SSR React using "Islands" and moving from webpack to Vite. I don't really understand what benefits this brings to HubSpot pages in particular over regular React, since HubSpot has extreme api rate limits (only allowed 4 calls per second across all visitors) and wondering if any of you can think of a use case.

prom candy
Dec 16, 2005

Only I may dance

hey mom its 420 posted:

Did y'all see Next 13? It looks really good. It's like we can finally write JS like we wrote PHP, but in a good way.

Yeah Next 13 is pretty cool. I was pretty hot for Remix but I think Next is gonna be the way forward. There's a bunch of stuff that's not yet supported in the new app folder though (i18n for one). Turbopack also seems legit.

abraham linksys
Sep 6, 2010

:darksouls:
the data fetching stuff next.js 13 is doing is also going to be a thing Remix starts adopting. it's all just stuff that was held back on react server components + suspense taking an extremely long time to develop (tbf: hard loving problem!), so I think a lot of these SSR frameworks that have focused on per-route loaders are now going to be moving to leaf-based loading

next seems ahead of the curve but also did the classic "let's launch our new version whenever we have our next big conference regardless of whether it's ready" thing so every single feature, including the new docs, is marked as "beta," so I look forward to adopting it in like six months. will be nice to replace a lot of gross code I've written to get everything loaded in getServerSideProps with leaf-based data fetching for sure

Roadie
Jun 30, 2013
For me, the one big thing still totally missing in Next as compared to Remix is form handling. Not "mutations" or any other fancy poo poo done through frontend JS, just plain form handling that will work right with a form POST from a static page.

Remix by comparison got this right from step 1 with "all mutations are just form submissions".

Adbot
ADBOT LOVES YOU

lazerwolf
Dec 22, 2009

Orange and Black
What’s the best framework for small web UIs,mainly for forms and data tables. I need to have graphql support.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply