Component returned from .map() not loaded in DOM


IWI

I'm trying to load some components into the DOM after a getcall . The console will confirm that the component is loaded into the variable, but the DOM will not be updated. Is there a grammar problem

const Blog: FC<BlogProps> = ({title, url}): ReactElement => {
    let response = [];
    let Posts = [];
    const {isDarkMode} = useContext(ThemeContext);
    function fetchBlogs(){
        let url = url;
        let count = 30;
        axios({
            method: 'post',
            url: '/api/grabIt',
            data: {
                url: url,
                count: count
            }
        })
            .then(function (res) {
                response = res.data.response;
                Posts = response.map(async function (item, i) {
                   return (<li><Post category={item.type} title={item.title} author={item.by} image={item.url} link={item.url} key={i}/></li>)
                })
            })
            .catch(function (error) {
                console.log(error)
            });
    }

    return (
        <>
            <div>
                <Button buttonColor={!!isDarkMode}
                        onClick={fetchBlogs}
                >FETCH</Button>
                <ul>
                    {Posts}
                </ul>
            </div>
        </>
    )
};

export default Blog

I've also tried just creating an array that is defined when the component loads (not after) and the DOM still won't update. i'm just empty<ul>

Dean

const Blog: FC<BlogProps> = ({ title, url }): ReactElement => {
    let response = [];
    const { isDarkMode } = useContext(ThemeContext);
    const [list, setList] = React.useState([]);
    function fetchBlogs() {
        let url = url;
        let count = 30;
        axios({
            method: 'post',
            url: '/api/grabIt',
            data: {
                url: url,
                count: count
            }
        })
            .then(function (res) {
                setList(res.data.response);
            })
            .catch(function (error) {
                console.log(error)
            });
    }

    return (
        <>
            <div>
                <Button buttonColor={!!isDarkMode}
                    onClick={fetchBlogs}
                >FETCH</Button>
                <ul>
                    {list.map((item, i) => {
                        return <li key={`row-${i}`}>
                            <Post category={item.type} title={item.title} author={item.by} image={item.url} link={item.url} key={i} />
                        </li>;
                    })}
                </ul>
            </div>
        </>
    )
};

export default Blog

Related


Component returned from .map() not loaded in DOM

IWI I'm trying to load some components into the DOM after a getcall . The console will confirm that the component is loaded into the variable, but the DOM will not be updated. Is there a grammar problem const Blog: FC<BlogProps> = ({title, url}): ReactElement

Component returned from .map() not loaded in DOM

IWI I'm trying to load some components into the DOM after a getcall . The console will confirm that the component is loaded into the variable, but the DOM will not be updated. Is there a grammar problem const Blog: FC<BlogProps> = ({title, url}): ReactElement

Component returned from .map() not loaded in DOM

IWI I'm trying to load some components into the DOM after a getcall . The console will confirm that the component is loaded into the variable, but the DOM will not be updated. Is there a grammar problem const Blog: FC<BlogProps> = ({title, url}): ReactElement

Component returned from .map() not loaded in DOM

IWI I'm trying to load some components into the DOM after a getcall . The console will confirm that the component is loaded into the variable, but the DOM will not be updated. Is there a grammar problem const Blog: FC<BlogProps> = ({title, url}): ReactElement

Knockout.js callback whenever a component is loaded into the DOM

Havardu I am writing a single page application using kickout.js. I want all textboxes in the application to behave in a certain way, for example, to select all the text currently in the set. To avoid duplicate solutions like adding custom bindings to all input

EmberJS component - run custom function after DOM is fully loaded

slap the key I'm trying to fully grasp the lifecycle of components. I've created a component, but I need a custom javascript function to run after the DOM is complete. I've gone through the EmberJS Docs and Stackoverflow, but none of the docs I've come across

Using the state of a component without react-router-dom loaded

Joey Fraum I reformatted the question with an example using the Star Wars API. The problem I'm having is trying to use state from PeoplePage and pass to CounterPage when using react-router-dom. Here is a small example of my real website. I'm trying to narrow d

Knockout.js callback whenever a component is loaded into the DOM

Havardu I am writing a single page application using kickout.js. I want all textboxes in the application to behave in a certain way, for example, to select all the text currently in the set. To avoid duplicate solutions like adding custom bindings to all input

EmberJS component - run custom function after DOM is fully loaded

slap the key I'm trying to fully grasp the lifecycle of components. I've created a component, but I need a custom javascript function to run after the DOM is complete. I've gone through the EmberJS Docs and Stackoverflow, but none of the docs I've come across

Knockout.js callback whenever a component is loaded into the DOM

Havardu I am writing a single page application using kickout.js. I want all textboxes in the application to behave in a certain way, for example, to select all the text currently in the set. To avoid duplicate solutions like adding custom bindings to all input

How to remove a component from the DOM?

Uzi I was wondering how to manually remove the component form DOM? I've been looking ElementRefand found some workarounds there, but I've been wondering if there is a function specifically for doing this? My setup is as follows: I have a component Loadercalled

How to remove a component from the DOM?

Uzi I was wondering how to manually remove the component form DOM? I've been looking ElementRefand found some workarounds there, but I've been wondering if there is a function specifically for doing this? My setup is as follows: I have a component Loadercalled

How to remove a component from the DOM?

Uzi I was wondering how to manually remove the component form DOM? I've been looking ElementRefand found some workarounds there, but I've been wondering if there is a function specifically for doing this? My setup is as follows: I have a component Loadercalled

Update dom from child component to parent component

SK Chanchol I am calling axios delete method in child component and want to refresh parent component to react. When delete() is called, it deletes the row from the database, but it needs to be reloaded manually. What if there is no manual reload? I want to rem

Update dom from child component to parent component

SK Chanchol I am calling axios delete method in child component and want to refresh parent component to react. When delete() is called, it deletes the row from the database, but it needs to be reloaded manually. What if there is no manual reload? I want to rem

Update dom from child component to parent component

SK Chanchol I am calling axios delete method in child component and want to refresh parent component to react. When delete() is called, it deletes the row from the database, but it needs to be reloaded manually. What if there is no manual reload? I want to rem

Update dom from child component to parent component

SK Chanchol I am calling axios delete method in child component and want to refresh parent component to react. When delete() is called, it deletes the row from the database, but it needs to be reloaded manually. What if there is no manual reload? I want to rem

Update dom from child component to parent component

SK Chanchol I am calling axios delete method in child component and want to refresh parent component to react. When delete() is called, it deletes the row from the database, but it needs to be reloaded manually. What if there is no manual reload? I want to rem

Update dom from child component to parent component

SK Chanchol I am calling axios delete method in child component and want to refresh parent component to react. When delete() is called, it deletes the row from the database, but it needs to be reloaded manually. What if there is no manual reload? I want to rem

Update dom from child component to parent component

SK Chanchol I am calling axios delete method in child component and want to refresh parent component to react. When delete() is called, it deletes the row from the database, but it needs to be reloaded manually. What if there is no manual reload? I want to rem

Get undefined props from component returned by getStaticProps

Kunal Rai I got a json response back from getStaticProps and the console logs it in getStaticProps to verify the correct json response. So the fetch works fine and I get the correct response from the API. import Layout from '../components/layout'; import fetch

Get undefined props from component returned by getStaticProps

Kunal Rai I got a json response back from getStaticProps and the console logs it in getStaticProps to verify the correct json response. So the fetch works fine and I get the correct response from the API. import Layout from '../components/layout'; import fetch

Get undefined props from component returned by getStaticProps

Kunal Rai I got a json response back from getStaticProps and the console logs it in getStaticProps to verify the correct json response. So the fetch works fine and I get the correct response from the API. import Layout from '../components/layout'; import fetch