Sunday, 20 September 2020

Iterating a Buffer object via .map() and passing data to a component via props

In my application I get a Buffer object with data from a file. For each byte in that buffer I want to render Bar and pass the byte as prop. However, the map function seems to have a problem with the Buffer object as Bar is not getting rendered at all. When I change data to an normal array everything works.

What am I doing wrong here?

import React from 'react';

function Bar(props) {
    return (
        <>
            {console.log(props.data)}
        </>
    )
}

function foo() {
  // var data = [0,1,2,3,4,5]
  var data = new Buffer([0,1,2,3,4,5])
  
  return(
    <div>
       {data.map((a) => {
          console.log(a) //correct data here
          return <Bar data={a} />;
       })}
    </div>
  )
}
```


from Iterating a Buffer object via .map() and passing data to a component via props

No comments:

Post a Comment