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.

Not returning a React Element

See original GitHub issue

I was following a tutorial on a simple react motion transition however I am getting the following error

bundle.js:4882 Warning: Transition(…): A valid React element (or null) must be returned. You may have returned undefined, an array or some other invalid object.

Here is the code for the Transition component `export default function Transition (props) { let defaultStyles = [], styles = []; const {children} = props; React.Children.map(children, (child)=>{

    if(child){
        defaultStyles.push({
            key: child.key,
            data: child,
            style: {opacity: 0}
        });

        styles.push({
            key: child.key,
            data: child,
            style: {opacity: spring(1)}
        })
    }
});

function willEnter() {
    return {opacity: 0}
}

function willLeave() {
    return {opacity: spring(0, {stiffness: 90, damping: 11})}
}

console.log(styles, defaultStyles);

<TransitionMotion styles={styles} defaultStyles={defaultStyles} willEnter={willEnter} willLeave={willLeave} children={props.children}>
    {
        (styles)=>{
            return(
                <div>
                    {
                        styles.map((child)=>{
                            if(child){
                                const {key, data, style} = child;
                                return React.cloneElement(
                                    data,
                                    {key, style}
                                )
                            }else{
                                return null
                            }

                        })
                    }
                </div>
            )
        }
    }
</TransitionMotion>

}`

and here is how I am trying to implement it

`class GroupItem extends Component{

render(){
    return(
        <Transition>
            {<div key="1">Hello there</div>}
        </Transition>
    )
}

}

Any help would be great `

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5

github_iconTop GitHub Comments

2reactions
bloodyowlcommented, Oct 27, 2017

https://jsfiddle.net/69z2wepo/89552/ there were some errors here, but the main one was that you didn’t return the TransitionMotion component

0reactions
takahiro-saekicommented, Nov 9, 2017

@Craques if you could resolve this problem, you might have better close this issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why my functions is not returning a component? React
I have a function that render LoginPage if the user is not logged and render the IndexPage if is logged, but ...
Read more >
How to return nothing from a React component
To return nothing from a React component, simply return `null`. When `null` is returned from a React component, nothing gets rendered.
Read more >
[Solved] React JSX function is not returning component - help
Hello, I have a meteor web app where I want to loop through the database and with the values from each element of...
Read more >
React Top-Level API
React.Children.only() does not accept the return value of React.Children.map() because it is an array rather than a React element. React.Children.toArray. React ...
Read more >
Return a Variable in the Render Function in React
Thus, the JSX elements can also get returned to the variable, and that variable can be used ... JSX with React is not...
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