動くコード図鑑技術記事現場の渡り方キャリア論すべての記事About
TypeScript

Container

出典: Typescript×ReduxでStateがundefinedに?確認すること!ソースコードを解説 / Container

Container (typescript)#adc8bd5d5619
import {ReduxAction, ReduxState} from "../Store/store";
import {DecrementAmount, IncrementAmount} from "../Actions/CounterAction";
import {connect} from "react-redux";
import {Dispatch} from "react";
import Counter from "./Counter";
 
export class ActionDispather{
	constructor(private dispatch: (action : ReduxAction) => void) {
	}
 
	public Increment() {
		this.dispatch(IncrementAmount())
	}
 
	public Decrement(){
		this.dispatch(DecrementAmount())
	}
}
 
export default connect(
	(state : ReduxState) => {
		return {value : state.Counter}
},
	(dispatch : Dispatch<ReduxAction>) => ({actions : new ActionDispather(dispatch)})
)(Counter)
▸ この snippet は実行結果未収録
▸ 実行結果は未収録です
  • id: #adc8bd5d5619
  • lines: 25
  • extracted: 2026-06-10

Source収録記事

この snippet は記事の「ソースコードを解説 / Container」セクションに登場する。コードの前後の文脈・ハマりどころの解説は記事本文で。

同じ記事から

11
図鑑トップ