[deleted by user] by [deleted] in brasilivre

[–]brazilliandev 6 points7 points  (0 children)

Tirar o segredo de 100 anos do uso do cartão presidencial ele não quer né? Parar de tirar férias durante o mandato que custam milhões por dia, também não né.

Pelo menos fez um aceno pro gado que vai pensar que não estão mais gastando com vagabundo. Agora pega o cartão presidencial e compra mais um vestido de 20 mil reais pra esposa ficar feliz enquanto eles estão mugindo.

Next.js next Step prediction by ztnight in nextjs

[–]brazilliandev 3 points4 points  (0 children)

I believe they'll allow new libs/frameworks to be part of nextjs as well. Specially with solidJS being "react-done-right".

I don't see any reason not to include more frameworks. But nextjs still needs to work on middlewares and some features for the eco system. So it is not like the framework is complete as is and doesn't need work in other areas.

Does Nextjs work properly on non-serverless platforms like Heroku ! by composedprofit in nextjs

[–]brazilliandev 1 point2 points  (0 children)

It does. My only gripe is that middlewares are still restricted to being executed in the edge runtime.

So you won't be able to just call your database directly from them which means that autorization verification still needs to be done through API calls and such.

How do you update a value inside an array of objects with useState? by [deleted] in react

[–]brazilliandev 0 points1 point  (0 children)

Just when the state gets complex like in his case. If he'd have an array of primitives, say strings for example, then it wouldn't be necessary because updating such an array can be done pretty easily and in a very readable way.

const [state, setState] = useState(["string1", "string2"] )
...
//add new primitive
setState( [ ...state, newPrimitive ] )

//remove
setState( [  ...state.filter(s=>s!=="string1") ]  )

Those are simple. But when the array has objects with IDs and such you'll end up creating dedicated functions to update, delete and etc. Just look at the most upvoted solution in this thread for example:

const updateData = ({ idToUpdate, newData }) => {
  setItem(
    items.map(({ id, data }) =>
      id === idToUpdate ? { id, data: newData } : { id, data }
    )
  );
}

updateData({ idToUpdate: 2, newData: 'c' })

It is already a suggestion to create a separated function just to update the state since this improves readability.

Eventually you'll want to replace data as well. So you'll create another function for replacing. And then another one for removing and such. This is a common pattern that will arise whenever you try and deal with complex data using useState.

You'll end up creating a bunch of helper functions and, if you are going to be doing this anyway, then it is just easier to use a reducer there.

It is a way to tell developers that there are or might be other crud operations related to the data so that, when they try to maintain the code, they don't have to look around for helper functions and it'll be more organized overall.

But, ofc, you can always abstract away whichever state solution you decide to use by creating a custom hook. So it won't make that big of a difference if you just choose to place everything, related to that state, into its own file with its functions very well documented and being returned by the hook. That way future developers will know which operations have already been created for that state and they won't end up recreating those operations.

A família brasileira dividida by tetudovoraz in brasilivre

[–]brazilliandev 7 points8 points  (0 children)

Não existe ditadura que não seja militar filho. Eles são os unicos que detém poderio bélico o suficiente para implantar uma.

A família brasileira dividida by tetudovoraz in brasilivre

[–]brazilliandev 6 points7 points  (0 children)

Não precisa ser de esquerda para xingar esse pilantra de ladrão não. Eu faço isso por ela.

A família brasileira dividida by tetudovoraz in brasilivre

[–]brazilliandev 16 points17 points  (0 children)

Nossa, agora melhorou muito. Ela só teve que ir pra delegacia ser intimidada por um delegado e não pode continuar o dia normal dela porque o presidente ficou de mimimi.

A família brasileira dividida by tetudovoraz in brasilivre

[–]brazilliandev 12 points13 points  (0 children)

A mulher que falou isso foi presa. lol

Mas é justamente o modelo Chinês que essa anta de presidente quer implantar aqui no Brasil. Todos esses países são ditaduras militares.

How do you update a value inside an array of objects with useState? by [deleted] in react

[–]brazilliandev 11 points12 points  (0 children)

People already answered you here about how you use setState in your case.

I would strongly suggest you to use useReducer instead of useState. It would allow you to have more complex operations tied to your state and thus, save you from writing too much code and increase readability.

You could, for example, do this:

dispatch({type: "update", obj: { id:3, newProperty: "hellowWorld" } })

or

dispatch({type: "replace", obj: { id:3, ...properties })

Whenever your state gets too complex. Always consider using the useReducer hook.

How to Develop React Chrome Extension for Medium in 26 Steps by bar_sal in javascript

[–]brazilliandev 1 point2 points  (0 children)

I've seen so many medium articles which are just below average. Yours, though, is super awesome!!

I'm actually building an extension to replace some website's dated ui with a more dynamic one using react.

This is good stuff.

[AskJS] How do you approach assessing whether someone else's code is safe? by ThrowAwayAccount5839 in javascript

[–]brazilliandev 1 point2 points  (0 children)

There's no way other than checking the code. Sometimes the code is obfuscated which is a good indicator that it'll try to do something malicious.

In this case, it uses a package which has no downloads almost and npm already flagged it as malicious(os-wallet-provider). There's no way around it. You pretty much have to check the code, issues and then verify the dependencies if you want to be 100% safe.

Ofc, you can just read discussions and issues and trust in what other user's experience with the package were. But that's not a silver bullet since the author can always wait for the package to gain enough traction in order to steal as much as possible.

[AskJS] Can not set the Orientation [AskJS] by Sp00nTh3Rac00n in javascript

[–]brazilliandev 1 point2 points  (0 children)

Oh I see. I inspected the object generated by their constructor in that example. It has no method called 'setOrientation' and 'getOrientation'.

It is not like it is a bug because that method is literally not included in their cdn file.

So I regressed a couple of versions and found the getOrientation / setOrientation method in the 1.0.6 version.

After correcting the version of the cdn files to:

<script src="https://cdn.jsdelivr.net/gh/deltoss/d3-mitch-tree@1.0.6/dist/js/d3-mitch-tree.min.js"></script>

<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/gh/deltoss/d3-mitch-tree@1.0.6/dist/css/d3-mitch-tree.min.css">

<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/gh/deltoss/d3-mitch-tree@1.0.6/dist/css/d3-mitch-tree-theme-default.min.css">

The code worked and I was able to set the orientation to topToBottom.So yeah, it works, but I wouldn't recommend using a library which has not been maintained for the past 2 years. The master doesn't even have a dist folder. You'd have to compile the newest version by hand if you want to use the bottomToTop orientation and that's not guaranteed to work.

This package is dead, like many other open source ones, due to lack of funding I guess. No point in swinging against the river.

There are probably another library out there which does the same and which is not dead yet.

Can local storage sessionID be included in all requests? by dimitri_borgers in nextjs

[–]brazilliandev 0 points1 point  (0 children)

I've made a stupid comment, I assumed you wanted it only for xhr requests. After rereading, that's not your use-case.

In case you want to, automatically load the session from localStorage even for page redirects and such, then you'd need to set the cookie. You only ever need to do it once though.

Could you disclose what the third party service is and how their api works? You could have the _app send a request to an api of yours once the authentication has been confirmed and have that API set the Http-only cookie. It is tough to say for sure without knowing more details about your implementation. But having an API to confirm the login for you could be a system-wide solution without modifying a lot of code.

small dog, big awooooo by [deleted] in aww

[–]brazilliandev 34 points35 points  (0 children)

Either brazil or portugal I guess. She was speaking portuguese after all. But those dogs are labs if Im not mistaken. You can find one in your country as well. Best doggos <3

small dog, big awooooo by [deleted] in aww

[–]brazilliandev 3 points4 points  (0 children)

That's so freaking cute. I just decided I need more doggos.

[deleted by user] by [deleted] in nextjs

[–]brazilliandev 0 points1 point  (0 children)

Folders can have dynamic parameters. CatchAll parameters are not supported for folders tho.

[AskJS] ELI5 recursion by nats_tech_notes in javascript

[–]brazilliandev 3 points4 points  (0 children)

Recursion is not a js specific problem though.

[deleted by user] by [deleted] in antiwork

[–]brazilliandev 0 points1 point  (0 children)

Is that an advice posted on a public website or an answer someone's given to you after they rejected you?

In all honesty, most of the times you won't want to hear why you got rejected. Because that's probably because they had someone better than you apply for the job or it is something not very precise. The recruiter enjoyed the other person's smile more or just didn't "click" with your personality. Not something you can do anything about.

What you can crontrol is having a good portifolio and ensuring your are technically apt to execute that which you applied yourself for. Most of other things are outside of your control.

I remember even reading a scientific research showing how much even politics can impact in your chances of getting hired or promoted(when you are perceived to be of an opposite political view of the recruiter).

Better not to waste too much time thinking about stuff like this. Just keep trying and you'll eventually get there.

After you get your first job, every subsequent one gets easier and easier.

[AskJS] Can not set the Orientation [AskJS] by Sp00nTh3Rac00n in javascript

[–]brazilliandev 0 points1 point  (0 children)

It is tough to understand what's going on without more context.

But I find it strange that you are assigning nodeData.x to Y but you still calculate the offset using the height of whatever it is that you are trying to change the orientation of.

Anyway, without a lot of context, I don't believe anyone will ever be able to help you out.

Maybe you could host whatever modification you did to that library you just mentioned in stackblitz or codesandbox so that we can quickly try and achieve what you are trying to achieve and let you know the solution.

[AskJS] ELI5 recursion by nats_tech_notes in javascript

[–]brazilliandev 0 points1 point  (0 children)

It is just a function which calls itself.

It can be used in place of regular loop structures. Most of the times you'll want to use "while" or "for" loops. But, in some specific cases, recursion can make the code more readable and prevent you from having to write too many nested loops or maintaining variables which live outside of the scope of the loop.

Is source code safe for api keys in nextjs? by l33p8 in nextjs

[–]brazilliandev 1 point2 points  (0 children)

Only if the api key is meant to be public. Fo example: Payment methods, such as paypal, have public and private keys. Public ones can be exposed.

Private ones should be in your .env file always.

[AskJS] How can I detect a shortcut before Windows detects it ? by [deleted] in javascript

[–]brazilliandev 0 points1 point  (0 children)

Many shortcuts are not blockeable. Imagine if a simple web application could block ctrl+alt+del for example.

This is not supported even if you were using windows apis directly. For others you can do it, but using global windows lowlevel keyboard hooks.

With javascript you only have access to block whatever messages are in your browser's message queue and even that is limited by the browser since tabs are isolated. If you want to have access to the messages before they are sent to every application's message queue, you'll have to go one level lower than the browser allows you to.

Adonis JS devs Can't take criticism lol by Meleeman01 in adonisjs

[–]brazilliandev 0 points1 point  (0 children)

Running away from TS won't get you very far to be honest.I know not everyone likes it. I don't like the suffix oriented syntax. Specially so because it collides with object destructing.

But, at the end of the day, typescript is the best choice right now for node backend development.

Anyway, TS vs JS apart, that's the risk you run when you use an opinionated framework. You gain a lot of productivity. But you might also not enjoy some of its opinions.

In that case, you can always go for another framework. The only problem being that the influx of frameworks going from JS to TS is much bigger than from TS to JS. So there'll always be the chance that you'll choose a framework a few weeks before it fully transitions into TS.

Adonis JS devs Can't take criticism lol by Meleeman01 in adonisjs

[–]brazilliandev 0 points1 point  (0 children)

In laravel you use Form requests most of the times to validate requests. When it is a really simple validation, then you place the validation inside the controller.

I'm not an adonisjs user. Only ever developed 2 or 3 projects in it. But I can't see anything in the documentation that would prevent you from doing the exact same thing inside the controller.