There are some cases where react project needs immutableJS to speed up it's performance. But it will screw up what react component code will be written as following code. Instead of the native dot operator , we do have to use immutable instance method(get,getIn,set,setIn) ,which will bloat the code and lost the benfefit of the intellisense and static check from IDE or Typescript.
I know there's an alternative lib seamless-immutable which can save my life.
But are there other simle ways out there in terms of using immutableJS in react component in the way we write the native javascript plain object.
/*Redux part is ommitted and assumed to be all converted to immutable structure */
class Exam extends Component {
constructor() {
super(...arguments);
}
componentDidMount() {
this.props.fetchHomeWorkList(); // ajax fetch data
}
render() {
return this.props.loading || !this.props.homeWorkList ? (
<Load />
) : (
this.props.homeWorkList.map(homework => (
<li>{homework.get("title")}</li>
{homework.get("subHomeWorkList").map(homeWorkEntity => (
<span>{homeWorkEntity.get("subTitle")}</span>
<span>{homeWorkEntity.get("content")}</span>
))}
))
);
}
}
const mapStateToProps = (state, ownProps) => ({
homeWorkList: state.getIn(["exam", "homeWorkList"]),
loading: state.getIn(["exam", "loading"])
});