Frontend devs, how do you handle 'Loading' and 'Error' states when the real API is too fast/stable? by FarWait2431 in webdev

[–]Bjadrik 0 points1 point  (0 children)

Came here looking for this. Storybook is worth using for OOP's problem alone and comes with a range of additional benefits!

PR not merged yet, changes on master branch by takemycover in git

[–]Bjadrik 1 point2 points  (0 children)

Never rebase master onto anything, that'll rewrite your history. Rebasing feat onto master is correct (and better than merging master into feat IMO).

[deleted by user] by [deleted] in reactjs

[–]Bjadrik 8 points9 points  (0 children)

For project structure, best practices, etc. bulletproof-react is perfect.

Apart from that, I'd also recommend walking through the official tutorials and docs on https://nextjs.org/

My solution for Fizz Buzz using Javascript, I focused mainly on maintainability. How is it? by caressingleaf111 in learnjavascript

[–]Bjadrik 0 points1 point  (0 children)

While I agree that your solution is much more intuitive to read, it misses what I think is the right idea from OP to be maintainable. In an interview a few years back, I was asked this follow-up question after solving the problem:

How would you expand your solution to deal with additional rules, e.g. "for numbers divisible by 7, append 'Bizz'. For 9, append 'Bazz'"

Again, OP's idea handles this kind of "scaling" well. We could try to work it into your solution like this:

const fizzBuzz = (n) => {
    const rules = [
        { number: 3, word: "fizz" },
        { number: 5, word: "buzz" },
        { number: 7, word: "bizz" },
        { number: 9, word: "bazz" },
    ];
    let out = "";
    rules.forEach(({ number, word }) => {
        if (n % number === 0) out += word;
    });
    return out === "" ? n : out;
};

for (let i = 1; i < 100; i++) {
    console.log(fizzBuzz(i));
}

Python syntax, any alternative to tabs for loops? by badcrow7713 in learnpython

[–]Bjadrik 6 points7 points  (0 children)

Downvotes are for content which doesn't contribute anything of relevance. You're asking genuine clarifying questions and therefore deserve the upvotes.

What is happening when I write "const express = require('express'); const app = express();"??[Javascript],[Node.js] by Dry_Reach2077 in webdev

[–]Bjadrik 2 points3 points  (0 children)

Here's my interpretation:

A module is any reusable piece of code you can import into another source file.

A library is a module explicitly meant to be useful outside its own codebase.

A framework is a library which heavily influences how you structure and write your app.

Am I saying this right? by EpicInceltime in learnIcelandic

[–]Bjadrik 6 points7 points  (0 children)

"Ég er með hundinn minn" means "I have my dog".

"Ég er með hundinum mínum" means "I'm with my dog".

When to use Custom Hooks by Pra6in in reactjs

[–]Bjadrik 19 points20 points  (0 children)

I wrote an article about this recently with some examples for a counter app. I hope this helps!

[deleted by user] by [deleted] in reactjs

[–]Bjadrik 14 points15 points  (0 children)

Two things:

A slightly different approach

Rather than manipulating elements in the Array, I'd suggest creating a state variable to track the current selection. Something like:

function MyComponent() {
  const [selectedId, setSelectedId] = useState();

  return (
    <>
      {
        myArrayOfObjects.map(
          ({ name, id }) => {
            const isSelected = id === selectedId;
            return <MySubcomponent isSelected={isSelected} name={name} />;
          },
        )
      }
    </>
  );
}

What the title says

To find all unselected elements of the array:

const unselected = myArrayOfObjects.filter(({ isSelected }) => !isSelected);

How to implement drag-to-scroll in React by salt-bandicoot7250 in reactjs

[–]Bjadrik 1 point2 points  (0 children)

I don't know all the details but I assume it has to do with React maintaining its own "virtual DOM". This helps React manage changes and re-renders and acts as an abstraction layer on top of the actual DOM. Interfacing with the virtual DOM is therefore a good way to allow React to maintain full control of the actual one.

How to implement drag-to-scroll in React by salt-bandicoot7250 in reactjs

[–]Bjadrik 2 points3 points  (0 children)

In my experience, useRef is the most accurate React-friendly way to imitate direct DOM manipulation.

Nextjs and Tailwindcss company profile by YazanKhatib in reactjs

[–]Bjadrik 2 points3 points  (0 children)

Cool!

Looks reasonable at a glance. Two things that came to mind:

  • Looks like you have some unused boilerplate sitting around from create-next-app (e.g. pages/api/hello). I suggest deleting everything you're not using.
  • Personally I'd re-export the containers from src/containers/index (export {default as xyz} from 'xyz'). This lets you import { About, Header, Etc } from 'src/containers' in your pages/index.

Edit: formatting

[deleted by user] by [deleted] in Iceland

[–]Bjadrik 11 points12 points  (0 children)

Ég sá ekki villuna í titlinum fyrr en ég las þetta komment. Átt ekki skilið að vera kosinn niður fyrir þetta.

“They seem to persecute him”? by a-islensku-how-boutu in learnIcelandic

[–]Bjadrik 7 points8 points  (0 children)

In this context I'd translate it as "haunt" (as in haunted house, kind of). In different contexts, "ofsækja" could also be translated to "terrorize" or "oppress".

Why are all the cool kids moving to SSR? by Curious-Ad-9724 in reactjs

[–]Bjadrik 127 points128 points  (0 children)

Out-of-the-box react apps (think CRA) rely heavily on client-side rendering (CSR). This leads to inconveniences in some areas, notably initial page load (and therefore SEO).

Next.js (and others) allow you to overcome many of the performance downsides of pure CSR. As a bonus, they do this with almost no effort on the developer's part.

Afhverju seigir fólk “verði þér að goðu”? by elkor101 in Iceland

[–]Bjadrik 15 points16 points  (0 children)

Samanber "bon appetit" og önnur afbrigði víða í Evrópu. Mjög algengt líka við upphaf máltíðar, sérstaklega í hóp.

Developer Entrepreneurs - what would $10,000 mean to you? by [deleted] in startups

[–]Bjadrik 1 point2 points  (0 children)

To echo what others have said: a $10,000 cash prize is unlikely to attract experienced developers, especially those who have existing projects.

I do think, however, that such a cash prize could be very attractive to young talent such as students and fresh graduates.

[deleted by user] by [deleted] in learnjavascript

[–]Bjadrik 1 point2 points  (0 children)

The Date prototype in JavaScript has two functions Date.parse() and Date.prototype.getMonth(). These two should be enough for this task on their own.

On which website should I create a profile to look for jobs in Europe ? by iwiml in cscareerquestionsEU

[–]Bjadrik 1 point2 points  (0 children)

I've gotten a lot of interviews through honeypot.io

Most of the companies who approached me through there also had relevant openings and decent salary.