1

I am trying to call a function to render table rows using the map function on an array of texts I receive as props but for some reason they are not being rendered. Am I making a syntactical mistake? I have verified that the license text props array is not empty and simply returns an array of strings.

const showLicenseText = () => {
 return licenseText.map(text => {
      <tr>
        <ThPadding>
          License Information
          {':'}
        </ThPadding>
        <td>{text}</td>
      </tr>
  })
}

The original code in render method is:

return (
  <table>
    <tbody>
      {bbbFileOpenDate && (
        <tr>
          <ThPadding>
            {text.bbbFileOpened}
            {':'}
          </ThPadding>
          <td>{bbbFileOpenDate}</td>
        </tr>
      )}
      {yearsInBusiness && !isOutOfBusiness && (
        <tr>
          <ThPadding>
            {yearsInBusinessLabel}
            {':'}
          </ThPadding>
          <td>{yearsInBusiness}</td>
        </tr>
      )}
      {businessStartDate && (
        <tr>
          <ThPadding>
            {businessStartDateLabel}
            {':'}
          </ThPadding>
          <td>{businessStartDate}</td>
        </tr>
      )}
      {showLicenseText}
      {locationStartDate && (
        <tr>
          <ThPadding>
            {locationStartDateLabel}
            {':'}
          </ThPadding>
          <td>{locationStartDate}</td>
        </tr>
      )} ....
2
  • maybe surround with return ( <tr> etc..</tr> ) ? Commented Aug 29, 2019 at 17:47
  • nope does not work Commented Aug 29, 2019 at 17:56

2 Answers 2

1

In your map you need to return your row. The map expects something returned

const showLicenseText = () => {
 return licenseText.map(text => {
      return (<tr>
        <ThPadding>
          License Information
          {':'}
        </ThPadding>
        <td>{text}</td>
      </tr>)
  })
}
Sign up to request clarification or add additional context in comments.

Comments

1

You forgot to call it! and In the map since you are using {} you need explicit return statement

  {showLicenseText()}

Also I would modify a little like below:

define function outside of render

showLicenseText = (licenseTextRef) => {
 return licenseTextRef.map(text => {
      return <tr>
        <ThPadding>
          License Information
          {':'}
        </ThPadding>
        <td>{text}</td>
      </tr>
  })
}

==============================

  {this.showLicenseText(licenseText)}

6 Comments

@Ackman do you get any errors? Do you have showLicenseText defined in your render() function?
yes that might be the case. It is defined inside. should I move it out?
Did it and did not help. still nothing.
If you move it out then you would have to reference it with this.
|

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.