Pass the value of a props from a function to render() in React.JS

Singh

I am making a get request from my React App to my backend. The call is successfull and I am able to receive the values from backend. However, I am not able to set the value to the front end DOM. Here is how my class currently looks:

class App extends React.Component{
    componentDidMount(){
        this.props.getData();
    }
    renderProds(){
        const data = this.props.products;
        if(data){
            data.map((e)=>{
                return (
                   <Product 
                      name={e.name}
                      desc={e.desc}
                   />
                );
            });
        }
    }
    render(){
        return(
          <div>{this.renderProds()}</div>
        )
    }
}

I've made sure that my Product component is imported correctly and it is accepting the props name and desc.

What am I doing wrong?

L_K

You should return something from your renderProds methods. Try this:

renderProds(){
        const data = this.props.products;
        if(data){
            return data.map((e)=>{ // return computed value
                return (
                   <Product 
                      name={e.name}
                      desc={e.desc}
                   />
                );
            });
        }
    }

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

Pass props to parent component in React.js

From Java

React JS: Pass A value from route to component

From Java

How to pass an object as props to a child Functional Component in React.js?

From Dev

Pass props from template into react.js root node

From Dev

React.js pass object key-value pairs as props

From Dev

React won't pass a particular value to "props"

From Dev

Pass value from filter as argument for js function in angular

From Dev

How to pass function groups as props in React?

From Dev

React JS Not Completely Updating View When Render Is Called With New Props

From Dev

How to access new props.value before render function in React life cycle

From Dev

React dangerouslySetInnerHTML to render an iframe youtube embed from props?

From Dev

How to pass a function through props in React to a function in a different component?

From Dev

React.js call recursive function in render

From Dev

How to pass react props/state of parent by reference, not value?

From Dev

best way to Pass Multiple Props In React js

From Dev

React won't pass a particular value to "props"

From Dev

Is there a way to pass string value to js file from View via function

From Dev

React.js, this.props.changeTitle is not a function

From Dev

pass a value to javascript function from angular js

From Dev

VueJS pass props to children in render function call

From Dev

How to pass props/state through Link and Route - react.js

From Dev

Render image from props in react,

From Dev

Get value from firebase and render it to render function in react

From Dev

How to pass a value from <a> (anchor tag) to a function in react js?

From Dev

Pass function from props to render function in react

From Dev

How to pass a component as props to another component in react js?

From Dev

pass props as a function doesn't work in a function react

From Dev

React pass props to onChange

From Dev

React.js return a style property from a function and use it inside the render() function

Related Related

  1. 1

    Pass props to parent component in React.js

  2. 2

    React JS: Pass A value from route to component

  3. 3

    How to pass an object as props to a child Functional Component in React.js?

  4. 4

    Pass props from template into react.js root node

  5. 5

    React.js pass object key-value pairs as props

  6. 6

    React won't pass a particular value to "props"

  7. 7

    Pass value from filter as argument for js function in angular

  8. 8

    How to pass function groups as props in React?

  9. 9

    React JS Not Completely Updating View When Render Is Called With New Props

  10. 10

    How to access new props.value before render function in React life cycle

  11. 11

    React dangerouslySetInnerHTML to render an iframe youtube embed from props?

  12. 12

    How to pass a function through props in React to a function in a different component?

  13. 13

    React.js call recursive function in render

  14. 14

    How to pass react props/state of parent by reference, not value?

  15. 15

    best way to Pass Multiple Props In React js

  16. 16

    React won't pass a particular value to "props"

  17. 17

    Is there a way to pass string value to js file from View via function

  18. 18

    React.js, this.props.changeTitle is not a function

  19. 19

    pass a value to javascript function from angular js

  20. 20

    VueJS pass props to children in render function call

  21. 21

    How to pass props/state through Link and Route - react.js

  22. 22

    Render image from props in react,

  23. 23

    Get value from firebase and render it to render function in react

  24. 24

    How to pass a value from <a> (anchor tag) to a function in react js?

  25. 25

    Pass function from props to render function in react

  26. 26

    How to pass a component as props to another component in react js?

  27. 27

    pass props as a function doesn't work in a function react

  28. 28

    React pass props to onChange

  29. 29

    React.js return a style property from a function and use it inside the render() function

HotTag

Archive