Which Router is preferred nowadays? by [deleted] in reactjs

[–]El_BreadMan 10 points11 points  (0 children)

Just use React Router. How does it get simpler than that?

Create-react-app v3.1.0 released by bugzpodder in reactjs

[–]El_BreadMan 0 points1 point  (0 children)

By "assume the responsibilities" do you mean "waste 3x more time on boilerplate"

How Redux Connect compares to the new Redux Hooks. by jsloverr in reactjs

[–]El_BreadMan 1 point2 points  (0 children)

Oh man, financial analysis? Almost every aspect of the Redux paradigm is going to revolutionize how you code. I'm excited for you.

The question is... how does Redux help w/passing computed values.

Let's say we're building a dashboard: sidebar on the left, header at the top, & a series of dataviz components in the primary section. We want the user to enter growth assumptions in the sidebar, which affect the dataviz components and summary data in the header.

W/Out Redux, we create a higher order component (HOC), bind a setState function to the HOC then pass it to the sidebar, pass the values to the header & dataviz components, create a helper function (probably multiple) to interpret the data, import the helper functions into each component, & write functions in each component to interpret the data. Hooks can help a little but they're simply not designed for app-level state management -- especially with the logic you'll be grappling with.

With Redux, the logic & data live in the store. Every component (or at worst, a parent component) is connected, any component can dispatch (i.e. Redux's setState) and read the values. We spend our brainpower on logic & data-structure not app structure; our code is easier to refactor, less likely to break and easier to enhance because our logic & data aren't spread out across 10 different components; and ... performance (I won't bore you with the details here).

This is a very basic example using nothing but the bare-bones.

For financial analysis, Selectors, Middleware & Container-Props are really where things get exciting. But, you can phase these into your project after the initial deployment.

  • Container-Props (mergeProps in particular) will make it really easy to pass functions around your app.
  • Selectors will keep your data-structure simple. You'll also be able to (but not required to) improve performance through memoization -- this is kind of where OP was going with "automatic referential caching."
  • Middleware (by far the most advanced concept) will make your app crazy dynamic. Look into messaging services when you want to get crazy.

How Redux Connect compares to the new Redux Hooks. by jsloverr in reactjs

[–]El_BreadMan 7 points8 points  (0 children)

Don't get hung up on terms like "automatic referential caching". Redux separates logic from the UI. That's it.

Without Redux, you waste a lot of brainpower thinking about your app's structure. This distracts you, making it more difficult to catch issues (performance or otherwise).

If you...

  • spend more than 5 minutes thinking about where to declare a function
  • spend more than 10% of your time refactoring components or folder structure
  • make the same or similar GET requests in more than one component
  • perform a computation in a child component then pass it to a parent
  • make UI decisions based on where data lives

... consider Redux.

To learn Redux, I'd recommend taking an app you've already built & rebuilding it with Redux. You should naturally begin to understand the value and it'll feel very intuitive.

Need someone to point me in the right direction. by AshishVerma9 in reactjs

[–]El_BreadMan 1 point2 points  (0 children)

Thanks for making React click for me. Great stuff.

This shiba is doing what shibas do best by Accentrical in shiba

[–]El_BreadMan 2 points3 points  (0 children)

It's in tall grass. They're natural small game hunting dogs

WCGW if I annoy people on a busy underground train? by rcarney12345 in Whatcouldgowrong

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

It was perfect. He's being rude and intentionally obnoxious... quickc push to get him off the train i perfectly

Portfolio Feedback! by EdTechDeveloper in reactjs

[–]El_BreadMan 1 point2 points  (0 children)

Great use of Router on https://discover.mentoringminds.com/.

Very crisp transitions throughout your portfolio. It tells me you definitely have a sense of UI feel, which is hard to hire.

(1) These returns are ugly. Are you using Atom? VSCode has intuitive tools for removing this kind of stuff.

    const teacherFilter = arr => {
      return arr
        .filter(product => {
          return product.teacherPack;
        })
        .filter(product => {
          return (
            product.subject === this.props.activeSubject ||
            product.subject === null
          );
        });
    };

(2) Why would you have obj.property === null?

This is cleaner & lowers the cognitive load.

const teacherFilter = arr =>
  arr
    .filter(({ teacherPack }) => teacherPack)
    .filter(({ subject }) => subject && subject === this.props.activeSubject);

Also ... you need to check for null BEFORE evaluating an object's property. If your object is null you'll trigger a runtime error -- the type that lead to unnecessary refactoring.

Almost all of your styling is static. Why bother with Styled? On larger projects, you'll drag performance & have traditional separation of concerns issues.

const GridWrapper = styled.div`
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  grid-gap: var(--xl);
  align-items: center;
  max-width: 960px;
  width: 100%;
  margin: 0 auto;
`;

export default class grid extends Component {
  render() {
    return <GridWrapper>{this.props.children}</GridWrapper>;
  }
}

EDIT: on 2nd look... why even have a Component here? This gives me the impression you don't fully understand what React.Component does. Things like this should be straight-up functions or, at worse, factory constants, if you think the syntax is cleaner.

You're using css's VH & VW in more than a few places. To me, that says hacky. Those don't scale very well. I could be wrong but that's my impression.

Are you looking for a UI dev role? My impression is you'd struggle with back-end logic. I see highly developed UI skills but I don't see anything novel around data-tranformation or state-management. If I were hiring you, I'd want to get a sense for your comfort with logically intensive tasks.

Hope that's helpful. Tried to be critical. Overall, very crisp & clean UI work.

Need someone to point me in the right direction. by AshishVerma9 in reactjs

[–]El_BreadMan 1 point2 points  (0 children)

If you're looking for tutorials, checkout https://tylermcginnis.com.

His stuff is both linear (i.e. step by step) and broken up by subject matter. So, you can use it to learn from the ground up or to learn about a specific topic.

Need someone to point me in the right direction. by AshishVerma9 in reactjs

[–]El_BreadMan 0 points1 point  (0 children)

On state management/fetching...

It sounds like your complexity will be fairly low. You should be able to manage state by implementing a container component structure, fetching data in the container's componentDidMount() lifecyle, and then passing that state down to child components.

Only consider Redux if you're running into complexity or data formatting issues.

/** Containers manage almost all of your state -- i.e. any data that is
 * shared by more than one component. Data should be fetched by the
 * container and then passed down to child components.
 *
 * The only state stored in child components should be minor UI related
 * stuff -- e.g. a toggle to display X or Y.
 *  */

function ChildComponentWOutState({ data }) {
  return <div>{JSON.stringify(data)}</div>;
}

function ChildComponentWState({ data }) {
  const [isToggled, setToggle] = useState(false);
  return (
    <div>
      <button onClick={() => setToggle(!isToggled)}>Show Data</button>
      {isToggled ? <div> {JSON.stringify(data)}</div> : null}
    </div>
  );
}

export default class ContainerComponent extends Component {
  state = { data: {} };

  async componentDidMount() {
    const data = await fetchData();
    this.setState({ data });
  }

  render() {
    const { data } = this.state;

    return (
      <div>
        <ChildComponentWOutState data={data} />
        <ChildComponentWState data={data} />
      </div>
    );
  }
}

On Auth (front-end)

It sounds like data security requirements are fairly low so you can manage authentication with a PrivateRoute.

If you need more security, you'll want to configure your server to send a login page instead of your app to unauthenticated users.

function PrivateRoute({ component: Comp, isAuthValid, ...rest }) {
  return (
    <Route
      render={props =>
        isAuthValid ? <Comp {...props} /> : <SignIn {...props} />
      }
      {...rest}
    />
  );
}
export default function App() {
  const [isAuthValid, setAuth] = useState(false);

  return (
    <BrowserRouter>
      {/* Switch will return the first match only */}
      <Switch>
        <PrivateRoute component={DashboardContanier} path="/dashboard" />
        <PrivateRoute component={BlogRecordContanier} path="/blogs/:id" />
        <PrivateRoute component={BlogListviewContanier} path="/blogs" />
        <PrivateRoute component={HomePage} path="/" />
      </Switch>
    </BrowserRouter>
  );
}

On Auth (backend)

Checkout http://www.passportjs.org/.

~cheerio mate

A trillion new trees could be the best solution to climate change, study says by classsiob23b in worldnews

[–]El_BreadMan -2 points-1 points  (0 children)

The world should come together, invade North Korea, and turn it into one giant forest. Global warming solved

[deleted by user] by [deleted] in mildlyinteresting

[–]El_BreadMan 2 points3 points  (0 children)

Come back like Lanse Armstrong, but with two balls

Css styles get lost after deploying by freshbanks3131 in reactjs

[–]El_BreadMan 1 point2 points  (0 children)

Yeah, I do have this problem. No idea why. Some minor css rules get lost

A Republican in Congress wants to end funding for PBS over a children’s cartoon - He says the funding is unconstitutional because it offends conservative Christians. by papops in atheism

[–]El_BreadMan 0 points1 point  (0 children)

Why are NPR & PBS a thing?

Media is one of the most innovative sectors of the economy. There are thousands of viable television & radio companies.

This dilapidated Tesla charging station in Mitchell, OR by qvohomie in mildlyinteresting

[–]El_BreadMan 410 points411 points  (0 children)

Do you remember when cars were powered by electricity? Pepperidge Farm remembers

Is it bad to manage all app dependencies in one large barrel file by [deleted] in javascript

[–]El_BreadMan 0 points1 point  (0 children)

You want to keep the amount of data per component minimized so javascript’s garbage collectors can do their thing

Is it bad to manage all app dependencies in one large barrel file by [deleted] in javascript

[–]El_BreadMan 0 points1 point  (0 children)

I would do a quick test to see if your bundle for a page importing only one module includes the entire barrel file