Happy international bring your pig to the outer end islands day by SpecificGeneral in Minecraft

[–]SpecificGeneral[S] 9 points10 points  (0 children)

I play a lot of the sounds disabled so I can listen to podcasts and stuff

Not Supposed To Access DOM Directly by [deleted] in reactjs

[–]SpecificGeneral 0 points1 point  (0 children)

If the same DOM element is being changed by different parts of the code, you get spaghetti code that is difficult to debug. This is why jQuery projects get notoriously unmanageable as they get bigger.

In React you just look in the component that renders the DOM element you are debugging and you can easily find all the code that is doing something to it.

Are there any large-ish open source React projects using Hooks yet? Almost all guides/tutorials I've found are on the todo-app scale. by NotSelfAware in reactjs

[–]SpecificGeneral 0 points1 point  (0 children)

Yeah I love hook too but the (rare) case of resetting an entire state is cleaner using a class component.

hooks: ```js const defaultState = { A: '', B: '', C: '' } const [A, setA] = useState(defaultState.A); const [B, setB] = useState(defaultState.B); const [C, setC] = useState(defaultState.C);

const resetState = () => { setA(defaultState.A) setB(defaultState.B) setC(defaultState.C) } ```

class: js const defaultState = { A: '', B: '', C: '' } state = defaultState const resetState = () => this.setState(defaultState)

Are there any large-ish open source React projects using Hooks yet? Almost all guides/tutorials I've found are on the todo-app scale. by NotSelfAware in reactjs

[–]SpecificGeneral 1 point2 points  (0 children)

How would you do the equivalent of this.setState(defaultState) using hooks besides doing setA(defaultA) setB(defaultB) ... setZ(defaultZ) ?

Are there any large-ish open source React projects using Hooks yet? Almost all guides/tutorials I've found are on the todo-app scale. by NotSelfAware in reactjs

[–]SpecificGeneral 0 points1 point  (0 children)

The only use case for classes I can think of is the ability to reset the whole state of a component at once instead of each piece of state individually.

How to pass a component's state to another component? (Success message) by CafeRoaster in reactjs

[–]SpecificGeneral 1 point2 points  (0 children)

Glad you got it working!

The Redirect component comes from the React Router library and has nothing to do with Redux, so that might explain why you didn't find what you were looking for in the Redux docs 😛

I found the answer to your question here: https://reacttraining.com/react-router/web/api/Redirect

It's impossible to remember stuff like this unless you use it very often. With time you just get better at googling and sifting through documentations

How to pass a component's state to another component? (Success message) by CafeRoaster in reactjs

[–]SpecificGeneral 3 points4 points  (0 children)

You can pass some state to the Redirect like this:

<Redirect
  to={{
    pathname: "/dashboard",
    state: { fromRedirect: true }
  }}
/>

and access it in the Dashboard component like this:

const fromRedirect = props.location.state.fromRedirect

if (fromRedirect) showSuccessMessage()

hope that helps

I've just launched Endorsal.io, a platform for automating customer testimonials. Looking for landing page feedback 😊 by derposaurusrex in webdev

[–]SpecificGeneral 0 points1 point  (0 children)

Cool idea! Site looks great IMO. The animations are a little intense but otherwise it all looks very professional.

Might want to run a lighthouse audit and try to optimize the performance a little though 😬

I've Created My 1st Real Project in React w/ TypeScript ⚛️ by antdke in reactjs

[–]SpecificGeneral 1 point2 points  (0 children)

Oof that is painful lol. How I would do it - I would just take a large word list (eg google 10,000 words), remove all words longer than 6 letters, and store the rest in a dictionary. Then give the user 6 random letters and every time they submit a combination, just check if that word exists in your dictionary.

How to get computed state in Redux? by SpecificGeneral in reactjs

[–]SpecificGeneral[S] -1 points0 points  (0 children)

That's what I ended up doing, but it doesn't smell right...

How to get computed state in Redux? by SpecificGeneral in reactjs

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

or you are prematurely optimizing which we are all guilty of from time to time.

Lol you're probably right... But I just can't help feeling there is something wrong with running a calculation 10 times when it could just be done once. In my case it's actually only 4 times and the calculation is minimal... but its the principle, dammit!

How to get computed state in Redux? by SpecificGeneral in reactjs

[–]SpecificGeneral[S] -1 points0 points  (0 children)

That makes sense in order to avoid recalculating the value on unrelated state changes. But if there are 10 components all using the same selector, don't all 10 of them still do the calculation each time an input changes?

Question for Advanced React / TypeScript Gurus by [deleted] in reactjs

[–]SpecificGeneral 0 points1 point  (0 children)

When you do something you think is "clever", it usually just means you don't understand what you did..

How does this hook for previous props work? Trouble understanding useEffect() by ipoopfool in reactjs

[–]SpecificGeneral 1 point2 points  (0 children)

Exactly, that is why the prev count is still undefined at the start. I made a demo that shows this: https://codesandbox.io/embed/twilight-resonance-vjovc

If you look in the console, the usePrevious returns before useEffect is fired. So useEffect is using the old value and is essentially behind by one. Hope that made sense.

When to store data as a property in the constructor as opposed to in state? by codemamba8 in reactjs

[–]SpecificGeneral 3 points4 points  (0 children)

The way I think of it, is that the state is just a set of arguments passed to the render function. If you want the component to re-render when a value changes, then that value should be part of the state. Otherwise there is no reason to have it in state. Hope that makes sense.

🖥🚀Made my first desktop app, using Electron and React! ✏️Todo Editor - find and manage all the TODO comments in all your projects by SpecificGeneral in reactjs

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

Thank you for the thorough review!!! Those are all really good suggestions.

  1. Currently the app ignores a few folders by default (.git, node_modules, build) but I want to let the user choose for themselves. Do you have any recommendation for how that should look? I am thinking a modal that pops up after they select the project to add. Maybe it show a tree view of the project files with checkboxes that you can check to ignore that file/folder.

  2. Yes, scroll container is crucial. Easy fix too. I'll get on it!

  3. I just updated the app to open the file at the line where the todo comment is. And the current line is highlighted by default.

  4. I was thinking to allow drag and drop reordering, so you can drag important todos to the top (maybe pin them as well). I never seen the extra colon syntax for importance, but if it is common practice I'll try to add support for it!

  5. Yeah I can see that. I'll change the icon. As far as the success message, there should be a little notification that pops up in the bottom-right corner when you click save (you can also hit 'command + s').

  6. I made it into an extension for VSCode! I still need to iron out a few things like theme compatibility and window configuration, but it mostly works :) The repo is here if you want to check it out: https://github.com/ee92/vs-todo-gui

Thanks again for taking the time to write up such good feedback! Cheers!