[SwiftUI TCA] Change state inside onAppear

Hello, I created simple view using TCA, but I cannot update the state within onAppear function, the state is not changing so the view not updated is it prohibited to change state inside onAppear?

Thanks before.

Text(viewStore.currentStep) // this should be updated every one second

public func reduce(into state: inout State, action: Action) -> EffectTask<Action> {
		switch action {
		case .viewAppeared:
                        state.isTimerOn = true
			return EffectTask(value: .toggleTimer(true)) // -> not working
		case .viewDisappeared:
			return .cancel(id: CancellableTask.timer)
		case .tickTock:
			state.currentStep -= 1
			if state.currentStep == 0 {
				state.isTimerOn = false
				return .cancel(id: CancellableTask.timer)
			return .none
		case .toggleTimer(let value):
			state.isTimerOn = value
			if state.isTimerOn {
				return EffectTask(value: .startTimerTask)
			} else {
				return .cancel(id: CancellableTask.timer)
		case .startTimerTask:
			return .run { sender in
				while !Task.isCancelled {
					try await Task.sleep(nanoseconds: 1_000_000_000)
					await sender(.tickTock)
			.cancellable(id: CancellableTask.timer)

You are allowed to change state inside onAppear.

You might like to compare your implementation with a similar example in the swift-composable-architecture repo here.

Hi @kiel If I moved the implementation of viewStore.send(.viewAppeared) inside onTapGesture {}, it works well, somehow it's not working in onAppear.