React rendering trello card names

Sudoscience

I have a react app which has a component as such:

import React, { Component } from 'react';
import '../css/TrelloCards.css';

class TrelloCards extends Component {
  componentDidMount() {
    const authenticationFailure = () => { console.log('Auth failure') };
    const trello = window.Trello;

    const getCards = () => {
      const error = (error) => {
        console.log(error);
      }
    const cards = (cards) => {
      console.log(cards);
    }
    trello.get('/member/me/cards', cards, error);
  }

  trello.authorize({
      type: 'redirect',
      name: 'React Trello',
      scope: {
        read: 'true',
        write: 'true' },
      expiration: 'never',
      success: getCards,
      error: authenticationFailure,
      response_type: 'token',
    });
  }

  render() {
    return(
      <h1>Placeholder</h1>
    );
  }
}

export default TrelloCards;

I've successfully console logged my cards, but now I want to render them on the page, I've tried

render() {
  return(
    <ul>
      {cards}
    </ul>
  );
}

I've tried mapping through cards like:

cards.map(card => {
  return(
    <li>{card.name}</li>
  );
}

But I get the error that 'cards' is not defined. I'm pretty new to React and programming in general, any help would be appreciated.

Mario Tacke

In your case render does not have access to the cards you downloaded through trello (they are only accessible within componentDidMount). One way to get around this is to save the downloaded cards to the react state. render will then be invoked because the state changed and the cards will be rendered.

Example

class TrelloCards extends Component {
  constructor() {
    this.state = {
      cards: []      <-------- define your initial state
    }
  }

  componentDidMount() {
    const trello = window.Trello;

    trello.authorize({
      type: 'redirect',
      name: 'React Trello',
      scope: {
        read: 'true',
        write: 'true' },
      expiration: 'never',
      success: () => console.log('auth success'),
      error: () => console.log('auth failure'),
      response_type: 'token',
    });

    trello.get('/member/me/cards', 
      (cards) => this.setState({ cards }),
                      ^----  set state here (shorthand)
      (error) => console.log('could not get cards'))
    }
  }

  render() {
    return(
      <div>
        {this.state.cards.map(card =>
          <li>{card.name}</li>)}
          ^---- render cards from state
      </div>
    );
  }
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

React components rendering with variable names

From Dev

Trying to add a card to trello fails

From Dev

Manatee.Trello: Card Webhook

From Dev

Add a custom property to Trello Card

From Dev

Trying to add a card to trello fails

From Dev

Manatee.Trello: Card Webhook

From Dev

Pulling Trello card members into google sheet

From Dev

Add trello card via html form

From Dev

How to set the color of a card cover in Trello API?

From Dev

Add Member to Card with Trello API and Python

From Dev

Pulling Trello card members into google sheet

From Dev

Unable with a Trello webhook to get infos card after card creation

From Dev

Does Trello provide a way to identify who created a card?

From Dev

How to post and retrieve comment card data through Trello API?

From Dev

Trello API: Show date on which a card's label was applied

From Dev

Trello API Moving Card to another List using Google Apps Script

From Dev

Store arbitary data against a card through the Trello API?

From Dev

Trello API Post new card error - Failed to execute 'postMessage' on 'DOMWindow'

From Dev

Window blinking with OpenGL rendering on NVIDIA graphics card

From Dev

Programatically selecting the best graphics card for DirectX rendering

From Dev

Window blinking with OpenGL rendering on NVIDIA graphics card

From Dev

Rendering a random card image: "Requiring unknown module"

From Dev

How to add unique integer short ID (feature number) for every card in trello?

From Dev

How to attach image(s) to a new Trello card from the JS client library?

From Dev

Modal rendering and onClick in React

From Dev

Simple React component not rendering

From Dev

React 0.13.1 rendering issue

From Java

Dynamically Rendering a React component

From Java

react rendering and state

Related Related

  1. 1

    React components rendering with variable names

  2. 2

    Trying to add a card to trello fails

  3. 3

    Manatee.Trello: Card Webhook

  4. 4

    Add a custom property to Trello Card

  5. 5

    Trying to add a card to trello fails

  6. 6

    Manatee.Trello: Card Webhook

  7. 7

    Pulling Trello card members into google sheet

  8. 8

    Add trello card via html form

  9. 9

    How to set the color of a card cover in Trello API?

  10. 10

    Add Member to Card with Trello API and Python

  11. 11

    Pulling Trello card members into google sheet

  12. 12

    Unable with a Trello webhook to get infos card after card creation

  13. 13

    Does Trello provide a way to identify who created a card?

  14. 14

    How to post and retrieve comment card data through Trello API?

  15. 15

    Trello API: Show date on which a card's label was applied

  16. 16

    Trello API Moving Card to another List using Google Apps Script

  17. 17

    Store arbitary data against a card through the Trello API?

  18. 18

    Trello API Post new card error - Failed to execute 'postMessage' on 'DOMWindow'

  19. 19

    Window blinking with OpenGL rendering on NVIDIA graphics card

  20. 20

    Programatically selecting the best graphics card for DirectX rendering

  21. 21

    Window blinking with OpenGL rendering on NVIDIA graphics card

  22. 22

    Rendering a random card image: "Requiring unknown module"

  23. 23

    How to add unique integer short ID (feature number) for every card in trello?

  24. 24

    How to attach image(s) to a new Trello card from the JS client library?

  25. 25

    Modal rendering and onClick in React

  26. 26

    Simple React component not rendering

  27. 27

    React 0.13.1 rendering issue

  28. 28

    Dynamically Rendering a React component

  29. 29

    react rendering and state

HotTag

Archive