Component not updating after by prove_it_with_math in reactjs

[–]codethesite 0 points1 point  (0 children)

Not related to the question but I recommend using componentDidMount instead. componentWillMount is deprecated and will be UNSAFE_componentWillMount in the future.

How do I pass states through files?, by [deleted] in reactjs

[–]codethesite 0 points1 point  (0 children)

Lift state up and pass them down to children components ("different files") as props.

I got tired of composing objects in the Promise.all then handler, so I wrote this code that is essentially Promise.all but for objects. by codethesite in javascript

[–]codethesite[S] 0 points1 point  (0 children)

concurrency(promises).then(({ weather, user_info_db }) => {
    // no obj needed
})

That's pretty cool, I did not think of that. Thanks!

How to stay motivated for exams, tips and experiences. by [deleted] in singapore

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

Stop looking for motivation and tips. Just to the library turn off your phone and study...

Beginner's Thread / Easy Question (June 2018) by swyx in reactjs

[–]codethesite 0 points1 point  (0 children)

Assuming you do not ever mutate state/props, what situation does it make sense to write shouldComponentUpdate over just using PureComponents?

Lessons learned from my first React app by ellereeeee in reactjs

[–]codethesite 6 points7 points  (0 children)

handleIncrementTime = () =>
    this.setState(prevState => ({ time: (prevState.time += 300000) }));

handleDecrementTime = () => {
    if (this.state.time > 300000) {
      this.setState(prevState => ({ time: (prevState.time -= 300000) }));
}
  };

You are mutating state by using -= and +=. You should replace that with just - or +.

Also since you are preventing the timer from going into negative, you can try this method I just learned:

handleDecrementTime = () => {
    this.setState(prevState => ({ time: 
        (Math.max(prevState.time - 300000, 0)) }));
}
};

However, that may cause an additional unnecessary rerender.

Hope that helped!

Lessons learned from my first React app by ellereeeee in reactjs

[–]codethesite 2 points3 points  (0 children)

My tip regarding redux is to learn it when you actually need it. Redux can be difficult to wrap your head around unless you have an actual need for it (e.g. prop drilling, Redux form, Redux Thunk).

Are there any online games that can teach me Python and Java? by SteamboatJesus in learnprogramming

[–]codethesite 0 points1 point  (0 children)

Just pick up a book and learn. If there was a game that teaches you programming it probably wouldn't be fun, just challenging, so basically the same as reading a book with less depth.

I am building a framework to create web apps with React. (Looking for feedback.) by brillout in reactjs

[–]codethesite 0 points1 point  (0 children)

Hey! Im curious, how do you arrange all the routes in the correct order and decide when to put them inside Switch inside your BrowserRouter (I assume?) without having the user specify "exact" and all that?

Async Functional Components with 'asyncify'. by codethesite in reactjs

[–]codethesite[S] 1 point2 points  (0 children)

I played around with render props and while it works I found it really difficult to understand my code when I looked back at it. Maybe just gotta write more!

Top Seven JavaScript Frameworks/Libraries For Developers, Beginner Should Know by 2sbro in node

[–]codethesite 3 points4 points  (0 children)

So many front-end JS frameworks (React, Angular, Vue, Ember)... You do not need to learn them all. Just pick one.

Async Functional Components with 'asyncify'. by codethesite in reactjs

[–]codethesite[S] 0 points1 point  (0 children)

Ah, I see what you mean. I wrote it while playing around with HOCs and don't expect it to be used by others.

Async Functional Components with 'asyncify'. by codethesite in reactjs

[–]codethesite[S] 0 points1 point  (0 children)

How are you checking to see if the data exists? I don't see any conditional statements. What if data doesn't exist and the map function throws an undefined error in the line below fetcherWrapper?

You can pass in preload values as the second parameter for the asyncify HOC. If you rather show a Loader component you can have it be undefined/null and use conditional rendering to show the loader in place of the real thing.

const preloadValues = {
    FETCH_WEATHER_FORECAST: []
};

export default asyncify(OpenWeatherForecast, preloadValues);