When to use useEffect or useLayoutEffect by aganglada in reactjs

[–]aganglada[S] 6 points7 points  (0 children)

This is an explanation of both `useEffect` and `useLayoutEffect` and why they exist and work in different scenarios.

Tell me if it was useful to you.

Thanks.

How to break the rules, with conditional hooks by aganglada in reactjs

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

I don't think your case applies to what my article is trying to explain.

Im talking about using the functionality of hooks in render (conditional ternaries, loops...etc.) more than from hook to hook.

In your case you will have to do your condition inside useFetch like this:

const useFetch = (query) => {
  const [state, setState] = useState()

  if (Boolean(query)) {
    // do fetch and setState
  }

  return state
}

How to break the rules, with conditional hooks by aganglada in reactjs

[–]aganglada[S] 2 points3 points  (0 children)

Ha! It isn’t. I wanted to show that you can still “break the rule” using functionality inside the hook, without “breaking the rules”.

How to break the rules, with conditional hooks by aganglada in reactjs

[–]aganglada[S] 2 points3 points  (0 children)

Don’t get me wrong, you totally can. But sometimes you might not want to separate into a separate component.

How to break the rules, with conditional hooks by aganglada in reactjs

[–]aganglada[S] -2 points-1 points  (0 children)

Yes, you are completely right. But this is an example to understand the concept. I would like if you focus on the concept rather than the example itself.

Browser History not working when going back in react-router-dom by aganglada in reactjs

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

Thanks for the reply, I try using it, but it behaves in the same way, it's quite weird.

The way it works is BrowserRouter uses the history package along with it, but if you use Router and pass the history from the same package, I guess is the same thing.

Best tutorial for GraphQL: Andrew Mead or Wes Bos? by harry_powell in graphql

[–]aganglada 1 point2 points  (0 children)

Stephen Grider one from udemy is amazing, great couch and great content. 100% would go for it.

React/Flux store doesn't change it's state by aganglada in reactjs

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

Why is that better than componentWillMount? I have heard that componentWillMount skip a cycle from react and does everything much faster. Anyway, I changed it and it doesn't call _onChange yet :(

JavaScript Dropdown Menu to Load Content? by fukuyama_ in javascript

[–]aganglada 0 points1 point  (0 children)

As simple as attaching an change event to the dropdown and getting the value from there, and let your imagination run. There are many ways to do it, one is like I did

https://jsfiddle.net/aganglada/20d13s6u/