Giter VIP home page Giter VIP logo

Comments (9)

afram avatar afram commented on July 20, 2024

Hi @rickyrauch

What does gallery.js look like?

from react-masonry-component.

rickyrauch avatar rickyrauch commented on July 20, 2024

Hello @afram

Exactly as your example.

var React = require('react');
var Masonry = require('react-masonry-component');

var masonryOptions = {
    transitionDuration: 0
};

var Gallery = React.createClass({
    render: function () {
        var childElements = this.props.elements.map(function(element){
           return (
                <li className="image-element-class">
                    <img src={element.src} />
                </li>
            );
        });

        return (
            <Masonry
                className={'my-gallery-class'} // default ''
                elementType={'ul'} // default 'div'
                options={masonryOptions} // default {}
                disableImagesLoaded={false} // default false
                updateOnEachImageLoad={false} // default false and works only if disableImagesLoaded is false
            >
                {childElements}
            </Masonry>
        );
    }
});

module.exports = Gallery;

from react-masonry-component.

afram avatar afram commented on July 20, 2024

This example expects elements to be passed into Gallery as a prop. I suspect this is where it's failing for you.

You probably want something more along the lines of:

var Gallery = React.createClass({
    render: function () {
        return (
            <Masonry
                className={'my-gallery-class'} // default ''
                elementType={'ul'} // default 'div'
                options={masonryOptions} // default {}
                disableImagesLoaded={false} // default false
                updateOnEachImageLoad={false} // default false and works only if disableImagesLoaded is false
            >
                { this.props.children }
            </Masonry>
        );
    }
});

Note how I use this.props.children inside Masonry

from react-masonry-component.

rickyrauch avatar rickyrauch commented on July 20, 2024

@afram Thanks for clarifying,

I still want to use this

  <li className="image-element-class">
    <img src={element.src} />
  </li>

from react-masonry-component.

afram avatar afram commented on July 20, 2024

No problem, that's easy done, though in a slightly different way to how you initially had it.

let elements = [
    {
        src: '/image1.jpg`
    },
    {
        src: '/image2.jpg`
    }
];

<Gallery elements={ elements } />

from react-masonry-component.

rickyrauch avatar rickyrauch commented on July 20, 2024

Yes, that's what I did.

I think the best approach would be:

<Gallery>
<ul>
  <li className="image-element-class">
    <img src={element.src} />
  </li>
  <li className="image-element-class">
    <img src={element.src} />
  </li>
  <li className="image-element-class">
    <img src={element.src} />
  </li>
</ul>
</Gallery>

Thanks.

from react-masonry-component.

afram avatar afram commented on July 20, 2024

That's really up to you :-)

I would ask the question "Why are images displayed in an unordered list?" - this example was largely to show people the component's flexibility.

Good luck, glad I could help :-)

from react-masonry-component.

rickyrauch avatar rickyrauch commented on July 20, 2024

I'm not saying <ul>, my example tries to show my own code. Instead of <ul> could be <div>. Parent (div or ul) and its childs (div or li)

from react-masonry-component.

afram avatar afram commented on July 20, 2024

No problem.

I'm closing this now as I hope I managed to answer your question.

Please reopen if you need to!

from react-masonry-component.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.