Skip to content

Commit c366fba

Browse files
committed
updating active at ListNote after being mounted
1 parent 30b0b39 commit c366fba

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/components/listNote.js

+13-3
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,24 @@ class ListNote extends Component {
88
super();
99
this.state = { active: -1 };
1010
}
11-
componentDidMount() {
12-
const { location } = this.props;
11+
_getActiveFromURL(props) {
12+
const { location } = props;
1313
const regex = /\/notes\/([0-9]+)(?:\/edit|$)/;
1414
const active = location.pathname.match(regex);
15+
return active ? Number(active[1]) : null;
16+
}
17+
componentDidMount() {
18+
const active = this._getActiveFromURL(this.props);
1519
if (active) {
16-
this.setState({ active: Number(active[1]) });
20+
this.setState({ active });
1721
}
1822
}
23+
componentWillReceiveProps(nextProps) {
24+
const active = this._getActiveFromURL(nextProps);
25+
if (active && active !== this.state.active) {
26+
this.setState({ active });
27+
}
28+
}
1929
render() {
2030
const { list } = this.props;
2131
const { active } = this.state;

0 commit comments

Comments
 (0)