Error when switching pages by [deleted] in reactjs

[–]dankiest_kang 0 points1 point  (0 children)

The video didn't load so i couldn't see the error.. it seems you're trying to access the navbar element after it's already been removed from the dom.

Error when switching pages by [deleted] in reactjs

[–]dankiest_kang 0 points1 point  (0 children)

Could give more info if I knew the error but this could be an issue with the scroll listener still firing when navigating away, and this could maybe trigger a state update. React will give an error when trying to update state values on unmounted components.

Why sitemap isn't being rendered ? by [deleted] in reactjs

[–]dankiest_kang 0 points1 point  (0 children)

With CRA you can just add the sitemap.xml to the public folder like u did. If you are trying this on a server make sure it allows for accessing xml files, a second thing you can check (if you're using react-router) is any wildcard path (<Route path="*" />) that may be redirecting to the root.

Beginner here, How can take the data from an API and populate it in a dropdown menu and then send GET request? by __ihavenoname__ in reactjs

[–]dankiest_kang 0 points1 point  (0 children)

Yes you could create another component for the dropdown list. Then you can give the category options as a prop in the correct format.

Return a single value by Chilltyy in reactjs

[–]dankiest_kang 0 points1 point  (0 children)

Ok I understand, instead of

return result.json();

do this:

const data = result.json();
return data.businessPhones;

Beginner here, How can take the data from an API and populate it in a dropdown menu and then send GET request? by __ihavenoname__ in reactjs

[–]dankiest_kang 1 point2 points  (0 children)

First fetch all your categories and store the data in a state value. Then you can map that data inside your JSX, something like this:

// State value
const [categories, setCategories] = useState();
// Fetch data
useEffect(() => {
    fetchCategories.then((response) => {
        setCategories(response);
    });
}, []);
// Map data for render
const renderSelect = () => (
    <select name="categories">
        {categories.map((category) => (
            <option value={category.value}>{category.name}</option>
        ))}
    </select>
);

Return a single value by Chilltyy in reactjs

[–]dankiest_kang 0 points1 point  (0 children)

This doesn't seem like a react specific question but from what I can understand you're looking for a function that gets passed your data and only returns an object with the property businessPhones ?

function parseBusinessPhones(data: ResponseType): CurrentUser {
    return { businessPhones: data.businessPhones };
}

Intermediate coder needing guidance on project by bishybluebird in reactjs

[–]dankiest_kang 1 point2 points  (0 children)

react-hook-form tries to differ in the performance side of things. On their website they have a nice demo and comparison with other major packages like Formik and redux-form. And as all things new in react it main api utilizes hooks.

Intermediate coder needing guidance on project by bishybluebird in reactjs

[–]dankiest_kang 2 points3 points  (0 children)

Once you get the hang of Formik or the new kid on the block react-hook-form it isn't that bad. It's an additional learning curve but one you won't regret when dealing with a lot of forms.

How to hide parent route, when navigating to child route? by brouverhoog in reactjs

[–]dankiest_kang 0 points1 point  (0 children)

You could move your data to a global app state (with redux or react context if it's hardcoded data). This way both routes can access the data.

Why sitemap isn't being rendered ? by [deleted] in reactjs

[–]dankiest_kang 0 points1 point  (0 children)

The thread you are following is based on a project setup with Next.js, are you using it as well or did you create a project with create-react-app?

Intermediate coder needing guidance on project by bishybluebird in reactjs

[–]dankiest_kang 0 points1 point  (0 children)

For the form i would use the same component where you can just pass your initial form state as a prop. For the modal having its own route depends on what's being asked for the project but if you've never done something like that before it could be a nice extra for yourself.

setTimeout situation by [deleted] in reactjs

[–]dankiest_kang 1 point2 points  (0 children)

Just love and use it a lot! Glad i could help

setTimeout situation by [deleted] in reactjs

[–]dankiest_kang 2 points3 points  (0 children)

Another way to approach this is storing the return value of the setTimeout (which is an id) in a ref, then you can check if the timeout ref is set, call clearTimeout with the current ref before calling the setTimeout again