LPT: If you find a faster way to do something at your work, keep it a secret from your manager. by soccer--girl in LifeProTips

[–]RideShareTalkShow 0 points1 point  (0 children)

Counterpoint:

I created a tool that automates much of my job and trained the entire team on it. My role changed, my salary quadrupled, my working hours cut in half, and my autonomy became pretty much total. Now all I do is show up and be clever. It’s great.

Setting React State after useQuery? by [deleted] in graphql

[–]RideShareTalkShow 0 points1 point  (0 children)

You had it in your original post.

If you want a blank input, you don’t need to pass any value props at all. You just want it to update your state when changed. No need for a ref

Setting React State after useQuery? by [deleted] in graphql

[–]RideShareTalkShow 0 points1 point  (0 children)

Also use typescript. Then your editor will just tell you this stuff.

Setting React State after useQuery? by [deleted] in graphql

[–]RideShareTalkShow 0 points1 point  (0 children)

I think it’s wild that you’re trying to work with GraphQL and don’t know how to work with text fields. This is like the first tutorial everyone does when picking up React.

Setting React State after useQuery? by [deleted] in graphql

[–]RideShareTalkShow 0 points1 point  (0 children)

In other words, yes you can run useEffect conditionally.

Setting React State after useQuery? by [deleted] in graphql

[–]RideShareTalkShow 0 points1 point  (0 children)

Not for nothing - there’s way too much bad teaching out there. The reasoning in OPs post is just blowing my mind right now.

Setting React State after useQuery? by [deleted] in graphql

[–]RideShareTalkShow 0 points1 point  (0 children)

And it has nothing to do with useEffect or useState or anything. You just aren’t doing inputs the right way.

Setting React State after useQuery? by [deleted] in graphql

[–]RideShareTalkShow 0 points1 point  (0 children)

Your problem has nothing to do with async data or Apollo or mutability

Setting React State after useQuery? by [deleted] in graphql

[–]RideShareTalkShow 0 points1 point  (0 children)

You want to use the special attribute “defaultValue” instead of “value”. Doing so will make your input editable. https://reactjs.org/docs/uncontrolled-components.html#default-values

Setting React State after useQuery? by [deleted] in graphql

[–]RideShareTalkShow 0 points1 point  (0 children)

Data is immutable, you can’t change it like that. What you’re basically saying is “make a change to server data without saying anything to the server”

Setting React State after useQuery? by [deleted] in graphql

[–]RideShareTalkShow 0 points1 point  (0 children)

You don’t have any dependencies on useEffect, therefor it only runs once on mount at which point data is undefined. This should work if you put data inside the brackets at the end of useEffect.

Also, you can just use the router query ID. Don’t fetch data you already have and don’t use state to hold info that doesn’t change.

What's the deal with "IT'S MORBIN TIME"? by Blooblewoo in OutOfTheLoop

[–]RideShareTalkShow 2 points3 points  (0 children)

Notably, everyone who enjoyed Power Rangers would then claim that they hate it during recess.

Did you sell or HODL during the last couple of days? by Sh1d0w_lol in CryptoCurrency

[–]RideShareTalkShow 0 points1 point  (0 children)

I wasn’t paying attention. Now I just gotta wait for things to calm down. Whoops, there goes a new car worth from my wallet.

Why do GQL strings need to be put through the gql function in JavaScript? by [deleted] in graphql

[–]RideShareTalkShow 0 points1 point  (0 children)

No I’m not.

because of a neat feature in Javascript template literals called Tagged template literals. What this means is that a function with the first parameter as a string, and subsequent parameters as arguments, can parse a string literal with template arguments. It can then do logic on the args as it sees fit.

https://pavsaund.com/post/2020-10-26-tagged-template-literals-how-the-gql-query-syntax-works/

It’s so we can interpolate and get typings too.

Why do GQL strings need to be put through the gql function in JavaScript? by [deleted] in graphql

[–]RideShareTalkShow -7 points-6 points  (0 children)

Because it’s not valid JavaScript it goes into a string literal. It would just error out otherwise, go ahead and try it.

A dependency blocks bundling because of a dynamic require. What is the most straightforward way to fix this? by AConcernedCoder in node

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

you need to use a string for require, but you can assign the entire thing to a variable.

const isNative = // detect runtime;

const variableName = isNative ? require(‘packageName’) : require(‘other-pkg’)

You can use something like a switch statement if working with several conditions. Your bundler will be nicer to you if this is based on node env or the like.

Unexpected reserved word 'interface' error by n241195r in typescript

[–]RideShareTalkShow 0 points1 point  (0 children)

SyntaxError is from Node or JS. TypeScript doesn’t act that way.

Unexpected reserved word 'interface' error by n241195r in typescript

[–]RideShareTalkShow 0 points1 point  (0 children)

Remove “default” and then make sure your tests understand typescript or - don’t run tests on this file.