Question: I am new to react and struggling to change the state of a component, and on the change replace the contents.

I have the following:

```js
function App() {

 const [page, setPage] = React.useState('list');

 switch(page) {
  case 'A':
   return(
   <body> 
    <Home />
    <A />
   </body>
  )
  case 'B':
  return(
   <body> 
    <Home />
    <B />
   </body>
  )
 }
}

function A() {

 return (
  <div>
   <div onClick={() => setPage('B')}>GoToB</div>
  </div>
 )
}

function B() {
    return (
       <div>test</div>
    )
}

```

There is a separate `Home` component that displays properly. How do I correctly call the `setPage` function to change the state so that the switch case is triggered and changes out the component?

Answer: 
Probably not an answer but this one would correspond more closely to the caption:

```hs
tSumToN :: (Enum a, Fractional a) => Int -> a -> a
tSumToN n = sum . take n . tSeq

tSeq :: (Enum a, Fractional a) => a -> [a]
tSeq x = 
  interleave odds evens
  where
    odds = [ o / x | o <- [1,3..]]
    evens = [ x / e | e <- [2,4..]]
    interleave [] _ = []
    interleave (y:ys) zs = y:interleave zs ys

example :: Double
example = tSumToN 4 1.1

```

btw: this one does obviously not converge mathematically so it seems rather pointless to take partial sums - but hey whatever
What you apparently meant was

```
recursion n x = if snd (properFraction (n / 2)) > 0   -- isOdd
                then x/n + recursion (n-1) (x**(-1))
                else n/x + recursion (n-1) (x**(-1))

```

but there's two problems here. First of all *correctness*, since you start from `n`th term and go back to `0`th, but use `x` as the starting value always, whereas it differs depending on whether `n` is even or odd. We fix problems like this by moving the actual work into the inner, "worker" function, and fixing the starting value of the iteration.

Second problem is that it is *not* *tail recursive*. We fix problems like that by introducing an accumulating parameter to the inner, "worker" function. One tool to fix two problems!

```
-- T = 1/x + x/2 + 3/x + x/4 + ...

recursion :: RealFrac a => a -> a -> a
recursion n x = if snd (properFraction (n / 2)) > 0   -- n is odd
                then goOdd  n 0
                else goEven n 0
  where
  goOdd  n acc     = goEven (n-1) (acc + n/x)
  goEven n acc 
       | n <= 0    = acc
       | otherwise = goOdd  (n-1) (acc + x/n)

```

Now it's correct, and tail recursive as you wanted.