10

I have below code for which

  1. import React, { Component } from 'react'; import factory from '../ethereum/factory';

    import ads_list from './ads_list'
    
    class showAds extends Component {
      static async getInitialProps(){
        let i;
        let a = [];
        const ad=await factory.methods.getAdress().call();
        const unique_address = Array.from(new Set(ad));
        for ( i = 0 ;i < unique_address.length;i++){
           a[i] = await factory.methods.getClientData(unique_address[i]).call();
        }
       console.log(a);
       return {a};
     }
    
     render(){
        return <div>
                 <p>{}</p>
              </div>;
        }
     }
    
     export default showAds;
    

for the above code I am getting below values in console.

   [ 
      {
        '0': 'www.google.com', 
        '1': 'Click here and enjoy searching', 
        '2': '17' 
      },
      { 
        '0': 'www.gmail.com', 
        '1': 'PLease login here', 
        '2': '2' 
      } 
      { 
       '0': 'www.google.com',
       '1': 'Click here and enjoy searching',
       '2': '17' 
      },
      { 
       '0': 'www.gmail.com',
       '1': 'PLease login here', 
       '2': '2' 
      } 
    ]

The problem I am facing is to print these values in front-end.

5
  • 1
    Can you provide correct data as array you mention is not valid Commented Apr 19, 2018 at 10:47
  • 3
    You can use this simple react component data => <pre>{JSON.stringify(data, null, 2)}</pre> developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/… Commented Apr 19, 2018 at 10:48
  • Do you want to print them all together or individually? Commented Apr 19, 2018 at 10:51
  • is your data similar to this object and array of it "Result" : [ {'0': 'www.google.com'}, {'1': 'Click here and enjoy searching'}, {'2': '17'} ] Commented Apr 19, 2018 at 10:51
  • OP, what have you tried? What specific troubles are you having in showing the data? This question almost sounds like you're asking how to use React Commented Apr 19, 2018 at 10:54

2 Answers 2

24

Using a simpler data as an example, you can render an unordered list like so:

class App extends React.Component {
  render() {
    const data = [
      {
        "0": "www.google.com",
        "1": "Click here and enjoy searching",
        "2": "17"
      },
    ];

    return (
      <ul>
        {data.map(item => {
          return <li>{item[0]}</li>;
        })}
      </ul>
    );
  }
}

CodeSandbox example here: https://codesandbox.io/s/j3y3q9pwr3

Sign up to request clarification or add additional context in comments.

Comments

3
JSON.stringify(["a", { b: "c" }])

See a demo.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.