-1

I am trying to display value of tinyui from the below response object which I'm receiving from a third-party confluence API via my in-house spring-boot API.

So the high level view, for example, is:

 "confluence-api"<--"spring-boot-api"<--"react-app"<---"user"

andthe JSON response is:

{
  "results": [
    {
      "id": "xxxxx",
      "type": "xxxx",
      "status": "xxxx",
      "title": "file",
      "restrictions": {},
      "_links": {
        "webui": "xxx",
        "tinyui": "",
        "self": "xxx",
      },
      "_expandable": {
        "container": "",
        "body": "",
        "version": "",       
        "space": "xxx"
      }
    },
  ],
  "start": 0,
  "limit": 25,
  "size": 9,
  "_links": {
    "self": "",
    "base": "",
    "context": ""
  }
}

However in my react app

import React, { Component } from "react";
import axios from "axios";

class Connect extends Component {
    state = {
        some:[],
        results:[],
      
    };

    componentDidMount() {
        const title = "sometext"
        axios.get(`http://localhost:xxxx/api/PageByTitle?title=${title}`,
            {
                headers : {
                    'Content-Type': "application/json",
                }})
            .then((res)=> {
                this.setState({ some: res.data?res.data:[]})
                this.setState({results:res.data.results?res.data.results:[]})
                console.log(this.state.some)
                console.log(this.state.some.results)
            })
            .catch(err => console.log(err))
    }

    render (){
        return(
            <div>
                {this.state.results.map(
                    (result) => <p>{result._links.tinyui}</p>
                )}
            </div>
        )
    }
}

export default Connect;

1 Answers1

0

the correct syntax for reading nested objects in webstorm is

{this.state.results.map((result)=><p key = {result.id}>{result['_links']['tinyui']}</p>)}

How to fight tons of unresolved variables warning in WebStorm?

JavaScript property access: dot notation vs. brackets?

Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
  • If the warnings in WebStorm are bothering you, just [disable them](https://stackoverflow.com/a/34485146/1218980). They usually have a hard time parsing different libraries, like React, that manages the state behind the scene. Using the bracket notation only hides the warning, but it also pollutes your code. – Emile Bergeron Mar 05 '21 at 21:43