question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

this.rerender() undefined

See original GitHub issue

Hi!

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:closed
  • Created 5 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
sonn-gammcommented, Oct 15, 2018

Ahah, yeah! You’re actually right — just tested 😅

Thanks @goto-bus-stop for the extra eyes on the code 👍

0reactions
goto-bus-stopcommented, Oct 15, 2018

In your first line you’re using:

el.firstElementChild.clientWidth

as the this.width value. But in the second line you’re multiplying by

el.firstElementChild.firstChild.clientWidth

that’s probably what’s causing the difference

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found