react-spring single-component mount/unmount reveals
up vote
0
down vote
favorite
i'm trying to create animation when component mount/unmount with React-spring:
import { Transition, animated } from 'react-spring'
...
export class CompName extends PureComponent<CompNamePropsType> {
static defaultProps = {
isExpanded: false,
}
render() {
const {
isExpanded,
...props
} = this.props
return (
<section className={styles.block} {...props}>
<Transition
from={{ opacity: 0 }}
enter={{ opacity: 1 }}
leave={{ opacity: 0 }}>
{isExpanded && (style => (
<animated.div style={{ ...style, background: "orange" }}>
<AnotherComp />
</animated.div>
))}
</Transition>
</section>
)
}
}
But this is just does not work and i got an error children is not a function
. What i did wrong, and how can i create animation on component mount/unmount with react-spring wrapper?
reactjs jsx react-spring
add a comment |
up vote
0
down vote
favorite
i'm trying to create animation when component mount/unmount with React-spring:
import { Transition, animated } from 'react-spring'
...
export class CompName extends PureComponent<CompNamePropsType> {
static defaultProps = {
isExpanded: false,
}
render() {
const {
isExpanded,
...props
} = this.props
return (
<section className={styles.block} {...props}>
<Transition
from={{ opacity: 0 }}
enter={{ opacity: 1 }}
leave={{ opacity: 0 }}>
{isExpanded && (style => (
<animated.div style={{ ...style, background: "orange" }}>
<AnotherComp />
</animated.div>
))}
</Transition>
</section>
)
}
}
But this is just does not work and i got an error children is not a function
. What i did wrong, and how can i create animation on component mount/unmount with react-spring wrapper?
reactjs jsx react-spring
IfisExpanded
is falsy it is returned as thechildren
props to theTransition
component which seems to expect a render prop, which you correctly return in t he caseisExpanded
is truthy. You can refactor this using a ternary operator and returning some kind of noop function whenisExpanded
is falsy.
– adz5A
Nov 9 at 15:35
@adz5A when isExpanded is 'true' error is ' TypeError: child is not a function', and if its 'false' - ' TypeError: _children is not a function'
– Vladimir Humeniuk
Nov 9 at 15:40
This is because the signature for thechildren
in your snippet is not correct. It is a function which returns a function:item => props => reactElement
. See react-spring.surge.sh/transition . Your example lacks theitems
props and a correct signature for thechildren
props.
– adz5A
Nov 9 at 15:53
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
i'm trying to create animation when component mount/unmount with React-spring:
import { Transition, animated } from 'react-spring'
...
export class CompName extends PureComponent<CompNamePropsType> {
static defaultProps = {
isExpanded: false,
}
render() {
const {
isExpanded,
...props
} = this.props
return (
<section className={styles.block} {...props}>
<Transition
from={{ opacity: 0 }}
enter={{ opacity: 1 }}
leave={{ opacity: 0 }}>
{isExpanded && (style => (
<animated.div style={{ ...style, background: "orange" }}>
<AnotherComp />
</animated.div>
))}
</Transition>
</section>
)
}
}
But this is just does not work and i got an error children is not a function
. What i did wrong, and how can i create animation on component mount/unmount with react-spring wrapper?
reactjs jsx react-spring
i'm trying to create animation when component mount/unmount with React-spring:
import { Transition, animated } from 'react-spring'
...
export class CompName extends PureComponent<CompNamePropsType> {
static defaultProps = {
isExpanded: false,
}
render() {
const {
isExpanded,
...props
} = this.props
return (
<section className={styles.block} {...props}>
<Transition
from={{ opacity: 0 }}
enter={{ opacity: 1 }}
leave={{ opacity: 0 }}>
{isExpanded && (style => (
<animated.div style={{ ...style, background: "orange" }}>
<AnotherComp />
</animated.div>
))}
</Transition>
</section>
)
}
}
But this is just does not work and i got an error children is not a function
. What i did wrong, and how can i create animation on component mount/unmount with react-spring wrapper?
reactjs jsx react-spring
reactjs jsx react-spring
asked Nov 9 at 15:30
Vladimir Humeniuk
315112
315112
IfisExpanded
is falsy it is returned as thechildren
props to theTransition
component which seems to expect a render prop, which you correctly return in t he caseisExpanded
is truthy. You can refactor this using a ternary operator and returning some kind of noop function whenisExpanded
is falsy.
– adz5A
Nov 9 at 15:35
@adz5A when isExpanded is 'true' error is ' TypeError: child is not a function', and if its 'false' - ' TypeError: _children is not a function'
– Vladimir Humeniuk
Nov 9 at 15:40
This is because the signature for thechildren
in your snippet is not correct. It is a function which returns a function:item => props => reactElement
. See react-spring.surge.sh/transition . Your example lacks theitems
props and a correct signature for thechildren
props.
– adz5A
Nov 9 at 15:53
add a comment |
IfisExpanded
is falsy it is returned as thechildren
props to theTransition
component which seems to expect a render prop, which you correctly return in t he caseisExpanded
is truthy. You can refactor this using a ternary operator and returning some kind of noop function whenisExpanded
is falsy.
– adz5A
Nov 9 at 15:35
@adz5A when isExpanded is 'true' error is ' TypeError: child is not a function', and if its 'false' - ' TypeError: _children is not a function'
– Vladimir Humeniuk
Nov 9 at 15:40
This is because the signature for thechildren
in your snippet is not correct. It is a function which returns a function:item => props => reactElement
. See react-spring.surge.sh/transition . Your example lacks theitems
props and a correct signature for thechildren
props.
– adz5A
Nov 9 at 15:53
If
isExpanded
is falsy it is returned as the children
props to the Transition
component which seems to expect a render prop, which you correctly return in t he case isExpanded
is truthy. You can refactor this using a ternary operator and returning some kind of noop function when isExpanded
is falsy.– adz5A
Nov 9 at 15:35
If
isExpanded
is falsy it is returned as the children
props to the Transition
component which seems to expect a render prop, which you correctly return in t he case isExpanded
is truthy. You can refactor this using a ternary operator and returning some kind of noop function when isExpanded
is falsy.– adz5A
Nov 9 at 15:35
@adz5A when isExpanded is 'true' error is ' TypeError: child is not a function', and if its 'false' - ' TypeError: _children is not a function'
– Vladimir Humeniuk
Nov 9 at 15:40
@adz5A when isExpanded is 'true' error is ' TypeError: child is not a function', and if its 'false' - ' TypeError: _children is not a function'
– Vladimir Humeniuk
Nov 9 at 15:40
This is because the signature for the
children
in your snippet is not correct. It is a function which returns a function: item => props => reactElement
. See react-spring.surge.sh/transition . Your example lacks the items
props and a correct signature for the children
props.– adz5A
Nov 9 at 15:53
This is because the signature for the
children
in your snippet is not correct. It is a function which returns a function: item => props => reactElement
. See react-spring.surge.sh/transition . Your example lacks the items
props and a correct signature for the children
props.– adz5A
Nov 9 at 15:53
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
The correct way is:
<Transition items={isExpanded} native from enter leave>
{isExpanded => isExpanded && (props => <animated.div style={props} />)
</Transition>
Items in, can be a single item like in your case, then work against the item that comes out. Reason for that is that transition will retain it, even when the actual state changes, it can still safely transition an element out on the "old" state.
The api is explained here: react-spring.surge.sh/transition
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
The correct way is:
<Transition items={isExpanded} native from enter leave>
{isExpanded => isExpanded && (props => <animated.div style={props} />)
</Transition>
Items in, can be a single item like in your case, then work against the item that comes out. Reason for that is that transition will retain it, even when the actual state changes, it can still safely transition an element out on the "old" state.
The api is explained here: react-spring.surge.sh/transition
add a comment |
up vote
1
down vote
accepted
The correct way is:
<Transition items={isExpanded} native from enter leave>
{isExpanded => isExpanded && (props => <animated.div style={props} />)
</Transition>
Items in, can be a single item like in your case, then work against the item that comes out. Reason for that is that transition will retain it, even when the actual state changes, it can still safely transition an element out on the "old" state.
The api is explained here: react-spring.surge.sh/transition
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
The correct way is:
<Transition items={isExpanded} native from enter leave>
{isExpanded => isExpanded && (props => <animated.div style={props} />)
</Transition>
Items in, can be a single item like in your case, then work against the item that comes out. Reason for that is that transition will retain it, even when the actual state changes, it can still safely transition an element out on the "old" state.
The api is explained here: react-spring.surge.sh/transition
The correct way is:
<Transition items={isExpanded} native from enter leave>
{isExpanded => isExpanded && (props => <animated.div style={props} />)
</Transition>
Items in, can be a single item like in your case, then work against the item that comes out. Reason for that is that transition will retain it, even when the actual state changes, it can still safely transition an element out on the "old" state.
The api is explained here: react-spring.surge.sh/transition
answered Nov 9 at 18:53
hpalu
1779
1779
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53228681%2freact-spring-single-component-mount-unmount-reveals%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
If
isExpanded
is falsy it is returned as thechildren
props to theTransition
component which seems to expect a render prop, which you correctly return in t he caseisExpanded
is truthy. You can refactor this using a ternary operator and returning some kind of noop function whenisExpanded
is falsy.– adz5A
Nov 9 at 15:35
@adz5A when isExpanded is 'true' error is ' TypeError: child is not a function', and if its 'false' - ' TypeError: _children is not a function'
– Vladimir Humeniuk
Nov 9 at 15:40
This is because the signature for the
children
in your snippet is not correct. It is a function which returns a function:item => props => reactElement
. See react-spring.surge.sh/transition . Your example lacks theitems
props and a correct signature for thechildren
props.– adz5A
Nov 9 at 15:53