Skip to content

Commit 8cc3b26

Browse files
committed
Fix demo mutated props and bad link; add component that updates own props.
1 parent 7df68f3 commit 8cc3b26

File tree

4 files changed

+57
-5
lines changed

4 files changed

+57
-5
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import React from 'react'
2+
import ReactCSSTransitionReplace from '../../src/ReactCSSTransitionReplace.jsx'
3+
4+
5+
class ChangeChildProps extends React.Component {
6+
7+
state = {
8+
text: 'one',
9+
key: 1,
10+
}
11+
12+
handleToggleText = () => {
13+
this.setState(state => ({
14+
text: this.getToggledText(state),
15+
}))
16+
}
17+
18+
handleAnimate = () => {
19+
this.setState(state => ({
20+
text: this.getToggledText(state),
21+
key: state.key + 1,
22+
}))
23+
}
24+
25+
getToggledText(state) {
26+
return state.text === 'one' ? 'two' : 'one'
27+
}
28+
29+
render() {
30+
return (
31+
<div style={{cursor: 'pointer'}}>
32+
<a onClick={this.handleAnimate}>Click to animate</a>
33+
{' | '}
34+
<a onClick={this.handleToggleText}>Change child props</a><br/>
35+
<br/>
36+
<ReactCSSTransitionReplace {...this.props}>
37+
<p key={this.state.key}>
38+
{this.state.text}
39+
</p>
40+
</ReactCSSTransitionReplace>
41+
</div>
42+
)
43+
}
44+
}
45+
46+
export default ChangeChildProps

demo/components/ContentAddRemove.jsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,13 @@ class ContentAddRemove extends React.Component {
1313
render() {
1414
const {style = {}} = this.props
1515

16-
style.cursor = 'pointer'
16+
const newStyle = {
17+
...style,
18+
cursor: 'pointer',
19+
}
1720

1821
return (
19-
<div style={style} onClick={this.handleClick}>
22+
<div style={newStyle} onClick={this.handleClick}>
2023
<a>Click to {this.state.added ? 'remove' : 'add'} content</a><br/>
2124
<br/>
2225
<ReactCSSTransitionReplace {...this.props}>

demo/components/ContentSwapper.jsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,13 @@ class ContentSwapper extends React.Component {
1515
const content = React.Children.toArray(this.props.children)
1616
const {style = {}} = this.props
1717

18-
style.cursor = 'pointer'
18+
const newStyle = {
19+
...style,
20+
cursor: 'pointer',
21+
}
1922

2023
return (
21-
<ReactCSSTransitionReplace {...this.props} style={style} onClick={this.handleClick}>
24+
<ReactCSSTransitionReplace {...this.props} style={newStyle} onClick={this.handleClick}>
2225
{content[this.state.index]}
2326
</ReactCSSTransitionReplace>
2427
)

demo/components/Demo.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ class Demo extends React.Component {
114114

115115
<h3 id="react-router-v4">React Router v4</h3>
116116
<p>Animating React-Router v4 transitions is supported. See the <a
117-
href="https://github.com/marnusw/react-css-transition-replace#cross-fading-two-components"
117+
href="https://github.com/marnusw/react-css-transition-replace#react-router-v4"
118118
target="_blank">example</a> for details.</p>
119119

120120
<AnimatedRouter/>

0 commit comments

Comments
 (0)