Reputation: 424
I have react class. This class in it's render method returns multiple HTML elements. On some of this elements I need to use function that will use 'this' of this element, not whole class.
// imports
class App extends Components {
render() {
const arr = ['one', 'two', 'three'];
const newArr = arr.map((val) => {
return <li id={IdFactory.register(val, getPath(THIS_LI))} key={val}>{val}</li>
})
return (
<ul>{newArr}</ul>
)
}
}
IdFactory.register takes a string and path to this element. Any idea how I can distinguish this element for the function?
Upvotes: 0
Views: 44
Reputation: 185
When you use arrow function it will not create its this context
Tip: If you ever want to find the context of this you can console.log it where you want to find
console.log(this)//Put where you want to find.
Upvotes: 1