0

I have a table which have a button and button have onClick() function, I am passing a method to onclick, But the ids are in an array.

i can console.log like props.requests[0].objectId.

const actionButton = (published) => {
    if (props.userType === 'crick') {
      if (props.data.verified) {
        return published === true ? <Label>Published</Label> : <Button basic onClick={() => scoreAction(// Have to pass ids here)} >Publish</Button>;
      }
    }
}

And the table is below from the above code.

   <Table.Body>
      {props.loanRequests.map((value, i) =>
    (<Table.Row key={i}>
      <Table.Cell> {value.cric.name}  </Table.Cell>
      <Table.Cell> {value.runs}  </Table.Cell>
      <Table.Cell> {actionButton(value.published)} </Table.Cell>
    </Table.Row>))}
   </Table.Body>

How can i pass the array of ids to the button's onclick function method.

Note : Semantic UI is in use.

2
  • Question updated. Commented Oct 30, 2017 at 13:46
  • Where are those ids? Commented Oct 30, 2017 at 13:48

1 Answer 1

2

Why not pass the entire object in to actionButton?

<Table.Cell> {actionButton(value)} </Table.Cell>

Then inside actionButton you can reference the properties.

const actionButton = (request) => {
    const {id, published} = request;
    if (props.userType === 'crick') {
      if (props.data.verified) {
        return published === true ? <Label>Published</Label> : <Button basic onClick={() => scoreAction(id)} >Publish</Button>;
      }
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.