Giter Club home page Giter Club logo

Comments (8)

felipethome avatar felipethome commented on June 3, 2024 1

I'm closing this issue because it is fixed in the major version update 2.0.0
@smirea just notice I also changed the API.

from react-inline-transition-group.

felipethome avatar felipethome commented on June 3, 2024

Hi @smirea. Is this happening with the version 1.1.0?

from react-inline-transition-group.

smirea avatar smirea commented on June 3, 2024

yep. it seems react is lazyly replacing the DOM element for subcomponents - which happens before you setAttribute in the 2nd example, and after you setAttribute in the first example

from react-inline-transition-group.

felipethome avatar felipethome commented on June 3, 2024

Can you tell me your React version? I tested your code here and worked as expected

from react-inline-transition-group.

smirea avatar smirea commented on June 3, 2024
"react": "^15.3.2",
"react-dom": "^15.3.2",
"react-inline-transition-group": "^1.1.0",

from react-inline-transition-group.

felipethome avatar felipethome commented on June 3, 2024

It is the same as me. I'm not being able to reproduce. Can you, please, submit your code somewhere?

from react-inline-transition-group.

smirea avatar smirea commented on June 3, 2024

Ok i figured out how to cause the issue. It only happens if a parent component updates on mount (e.g. setState in componentWillMount). The initial state will be invalid but the second the parent updates everything is fixed.

Here is the full code:

import React, {Component} from 'react';
import Transition from 'react-inline-transition-group';

export default class App extends Component {

    state = {};

    handleRef = elem => {
        this.setState({rand: Math.random()})
    }

    render () {
        return (
        <div ref={this.handleRef}>
            <TransitionTest />
        </div>
        );
    }

}

class TransitionTest extends Component {

    state = {
        list: '1234567890'.split(''),
    };

    render () {
        const {list} = this.state;
        const TestClass = (props) => <div {...props} />

        return (
        <div>
            <div onClick={() => this.setState({list: [Math.random()].concat(list)}) }> ++ add ++ </div>
            <Transition
                childrenBaseStyle={{
                    background: 'red',
                }}
            >
                {list.map((val, index) => {
                    const props = {
                        key: val,
                        onClick: () => this.setState({list: list.filter(v => v !== val)}),
                    };
                    return index % 2 === 0 ?
                        <TestClass {...props}>{val}</TestClass> :
                        <div {...props}>{val}</div>
                })}
            </Transition>
        </div>);
    }

}

You should see half the rows red and half white. if you add/remove anything the state becomes valid.

If you remove the setState() from handleRef() the state is also initialized valid

from react-inline-transition-group.

felipethome avatar felipethome commented on June 3, 2024

I believe the problem starts with the stateless component you are using.

When I apply the styles I do it manually using the setAttribute(). React stateless components are optimized in some ways that I'm not aware of, but they probably are caching the component definition since it is just a function. And in your definition const TestClass = (props) => <div {...props} /> the styles are not yet present

I found a way to fix this, but I need to be sure of the side effects. In the meantime you can avoid using stateless components.

from react-inline-transition-group.

Related Issues (10)

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.