-
Notifications
You must be signed in to change notification settings - Fork 593
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
holder.js does not work when the page renders twice in React #225
Comments
@cindy100295 could you provide a fiddle or a Gist (or anything that works for you) of the page? in the meantime, i think one thing you could try is change this: Holder.run({
images:"MyClassName"
}) to this: Holder.run({
images:".MyClassName" // should be .proj-card-img if going by your comments
}) note the . before the class name, as the |
My code in index.html:
In React Component:
But this time it does not show anything. Some background: I have five cards, two of them are loaded from a JSON file (local). Three of them I pulled from Firebase (remote). Every time the two local cards render first. Then the other three show up later. Holder.js work for the local two but not for the remote three. If I wrote the code above, five cards have no placeholder images. |
could you try something like this instead: componentDidMount: function () {
requestAnimationFrame(function () {
Holder.run({
images: '.proj-card-img'
});
});
} also, as a followup, you could try passing a Node (Element) to |
Thanks! I figure it out.
In component:
And then it works. |
nice @cindy100295 i'll look into adding this to docs |
i used mine without the didmountComponent.... like this |
I struggled to get holderjs 2.9.7 (https://www.npmjs.com/package/holderjs) working nicely in react bootstrap 1.4 (bootstrap 4.5.3). I was trying to use it in a class component. In the end this worked:
Then in my component:
And on the image:
|
cool @nimbus2300 - glad you got it working. will keep that in mind when there's a native react component |
Hi,
Have fun. |
According to imsky/holder#225 (comment) holderjs.run argumen can be a string of targeted element classes. Don't know if this is a recent of holderjs change but this .d.ts dosen't work with holderjs as is and makes it unusable with a react ts setup.
yoieh:patch-1 |
* Holderjs.run options can be a string According to imsky/holder#225 (comment) holderjs.run argumen can be a string of targeted element classes. Don't know if this is a recent of holderjs change but this .d.ts dosen't work with holderjs as is and makes it unusable with a react ts setup. * extended holderjs test to just run with a string * run() can alsow be empty Made options optional * Removed missleading options as string
It only seems to work when I go to a URL, but when I use the react router to change the content of div for example with a navbar, it doesn't load.
|
@nimbus2300 Thanks that solve it for me eventually. I think I understand it too, learning... was confused by runHolder... it's really run holder.js not a holder of run operations, lol, was confused. One thing I can't understand and google can't find is how this image-class-name-no-initial-dot class or 'userOptions' argument works. |
I am using holder.js in React with react-bootstrap. In
index.html
I added in<header>
:<script src="holder.js"></script>
In the component
ProjectCard
I wrote:<Card.Img className="proj-card-img" variant="top" data-src="holder.js/100px180" />
This component is rendered using map() function
It works nicely if I set state in
ComponentWillMount()
. However, if I update the state and the page renders twice (e.g. use firebase to syncState), holder.js will not work.I have tried
but it didn't work either.
Did I write anything wrong? Thanks!
The text was updated successfully, but these errors were encountered: