use function composition instead of mutable state

As React is functional programming-based library we need more functional examples