TTC
Theo's Typesafe Cult低级黑小明👑
variable initialized useState as true but the state is false
hasReaction is true, but liked is false
error gets printed multiple times
const hasReaction = postWithUser.reactions.some(
(reaction) => reaction.userId === user?.id ?? ""
);
const [liked, setLiked] = useState(hasReaction);
if(hasReaction !== liked) { console.log('error'); } I'm calling this in side each tweet component Is this common and is it supposed to happen? maybe it has sth to do with life cycles?
const [liked, setLiked] = useState(hasReaction);
if(hasReaction !== liked) { console.log('error'); } I'm calling this in side each tweet component Is this common and is it supposed to happen? maybe it has sth to do with life cycles?
K
korgko•367d ago
if
postWithUser
is a prop or some outer state that you pass down it could be possible that on the initial render it's value is being set to false
and later on changes to true
, therefor when your initial useState value is set it will be set to false
but hasReaction
will be equal to true
低级黑小明👑•367d ago
thanks for the insight. I'm pretty sure that I didn't change the state anywhere, and the initial value shouldn't be changed. it seems like the .some statement has something to do with it. I changed it to const hasReaction = postWithUser.reactions.length > 0;
and it worked. Not sure why tho
what I'd really like to know is if there's some kind of pitfall in this react system which caused this, because changing the code didn't solve the problem in call places
21KMembers
View on DiscordWant results from more Discord servers?
More Postscreate-t3-turbo monorepo: How to access user session to packages/db?I would like to access some props from user's session to **prisma middleware**
i.e. in below exampleCreating an update mutation with tRPCHi everyone, I'm trying to use an update mutation in this way:
```ts
export const beerRouter = creatCreate and Download PDFI have a web app that allows users to edit a table including drag/dropping rows, change row colors, Is it possible to pass a zod schema as a prop?I have this
```ts
interface Props {
schema: ZodSchema;
children: React.ReactNode;
defaulLoading state of a `'use server'` componentIs it possible to have a loading state for e.g. a form submission using the new `use server` directiHow do you self host your projects in a vpswithout relying on any cpanel or vercel,
i have a vps and i usually move the project using git and Geniune question: php vs server componentsI love nextjs. I hear a lot of comments about nextjs just reinvented php. Can someone clarify thingsHow do you fetch an svg from s3 into an angular app?I tried several things, but each time the svg isn't displayed.What's this errorit was working till yesterday then i added stateDistrict to address model then i started to get thisPrisma find many undefinedHello,
In my other projet when i do `prisma.resource.findMany({select: ...})` the type is `{id: str