У меня есть исходный массив: 1, 2, 3, 4, 5, и я хочу добавить 1 к каждому элементу в массиве.
Код выглядит следующим образом:
import React from 'react';
import { from } from 'rxjs';
import { map } from 'rxjs/operators';
class App extends React.Component {
constructor(props) {
super(props);
this.state = {
fromArray: [1, 2, 3, 4, 5]
};
}
componentDidMount() {
const observable$ = from(this.state.fromArray).pipe(
map(value => ({
observable: value + 1
}))
);
this._subscription = observable$.subscribe(
result => this.setState({...result})
)
}
componentWillUnmount() {
this._subscription.unsubscribe();
}
render() {
const { fromArray } = this.state;
return (
<ul>
{
fromArray.map((item, index) => <li key={index}>{item}</li>)
}
</ul>
)
}
}
export default App;
Но у меня есть только начальный массив в списке.
Как заставить это работать?