this.rerender() undefined
See original GitHub issueHi!
Noob here so I might just be missing something obvious or complicating things for no reason.
I am in a situation where I have to create a choo component that sets its width
and height
values by first loading an image as a child node, and then using that image to defines width
and height
of the root node. That works.
The problem comes when I add a resize
EventListener
and try to rerender()
the component. If I log the function this.rerender()
I always get undefined.
Some relevant code (file here):
load (el) {
const resize = () => {
if (el.firstChild.firstChild.nodeName.toLowerCase() === 'img') {
this.width = el.firstElementChild.clientWidth
this.height = (el.firstElementChild.firstChild.dataset.height / el.firstElementChild.firstChild.dataset.width) * el.firstElementChild.firstChild.clientWidth
} else {
this.width = el.firstElementChild.firstChild.clientWidth
this.height = (el.firstElementChild.firstChild.firstChild.dataset.height / el.firstElementChild.firstChild.firstChild.dataset.width) * el.firstElementChild.firstChild.firstChild.clientWidth
}
this.rerender.bind(this)()
console.log( this.rerender.bind(this)() )
}
resize()
window.addEventListener('resize', function () {
resize()
})
}
update (el) {
return true
}
and how I create the component (file here):
function entry (state, emit) {
return ov(page[0].children).map(function (item, i) {
var card = state.cache(Card, i)
return card.render(state, emit, item, i, state.cards[i])
})
}
Could it be that state.cache
does not see that I am changing the width
and height
values when resizing the page, so… I should be explicit about that?
Thanks, af
Issue Analytics
- State:
- Created 5 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
React Prop Becomes Undefined on Re-render
The reason is that i will keep changing for each iteration, but () => this._onBrigadePosSelection(i) is dynamically called function.
Read more >React 18 allows components to render 'undefined'
React now allows undefined to be rendered. ... //App.jsx function App() : ComponentType { return(<Shape type="rectangle"/>) } //Rectangle is ...
Read more >isLoading gets true, user gets undefined and ...
Platform Version: i m using react version 17; Code Snippets/Error Messages/Supporting Details/Screenshots: Failed to load resource: the server ...
Read more >React JS UNDEFINED Solution | Reactjs Learning - YouTube
As a React JS developer, have you encountered such errors?- TypeError: Cannot read property 'map' of undefined - Map is not a function-...
Read more >props.data is undefined in child functional component React JS
Hello Guys, In this video I have described how to fix error props.data is undefined in the function component in React JS project....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Ahah, yeah! You’re actually right — just tested 😅
Thanks @goto-bus-stop for the extra eyes on the code 👍
In your first line you’re using:
as the
this.width
value. But in the second line you’re multiplying bythat’s probably what’s causing the difference