Not returning a React Element
See original GitHub issueI 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:
- Created 6 years ago
- Comments:5
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
https://jsfiddle.net/69z2wepo/89552/ there were some errors here, but the main one was that you didn’t return the
TransitionMotion
component@Craques if you could resolve this problem, you might have better close this issue.