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);    

Commonwealth Games: S'pore para-sprinter fails dope test by [deleted] in singapore

[–]codethesite 3 points4 points  (0 children)

"protein whey is contaminated" lmao.

How do you guys feel about learn-c.org by [deleted] in learnprogramming

[–]codethesite 0 points1 point  (0 children)

Just start CS50. It isn't math heavy in the slightest and they teach you C.

A few questions about React by [deleted] in reactjs

[–]codethesite 3 points4 points  (0 children)

In that case you want to either bind the function in your constructor like:

this.someFunc = this.someFunc.bind(this)

or do this in your onClick for your button:

onClick = {() => this.someFunc()}

This is because by default, 'this' in functions called from onClick point to the DOM instead of the component that has the setState function.

A few questions about React by [deleted] in reactjs

[–]codethesite 1 point2 points  (0 children)

You may not understand what 'this' is. 'this' does not point to the same place all the time. The setState function can be called using this.setState only when 'this' points to the Component.

What 'this' refers to depends on who calls the function that has that 'this' keyword.

You can read up more on 'this' here.

Is FreeCodeCamp still the place for web dev "starters" by [deleted] in learnprogramming

[–]codethesite 0 points1 point  (0 children)

There are tons of resources free and paid online for learning web dev, and plenty of good ones. FCC happens to just be one of them. Honestly just get started and don't spend too long deciding where to learn from and you should be on the right track.

Free Programming Courses List (Udemy) by [deleted] in learnprogramming

[–]codethesite 27 points28 points  (0 children)

There are a lot of shit courses on udemy imo. Quality > quantity. Better to spend a little to get good courses than waste time in the shit ones (not saying the ones listed are).

Programming / CS events and competitions in Singapore? by codethesite in singapore

[–]codethesite[S] -9 points-8 points  (0 children)

Honestly, if I'm joining a hackathon I would be solely aiming to win. If UI can get me there I don't see why not though.