// the store and reducerimport{createStore}from"redux";import{connect}from"react-redux";letreducer=(state,action)=>{if(action.type==="LOADED_INVOICE"){return{...state,invoice:action.data,};}returnstate;};letstore=createStore(reducer);/////////////////////////////////////////////// the actionfunctionfetchInvoice(dispatch,id){fetch(`/invoices/${id}`).then((response)=>{dispatch({type:"LOADED_INVOICE",data:response.json(),});});}/////////////////////////////////////////////// the component, all connected upclassInvoiceextendsReact.Component{componentDidMount(){fetchInvoice(this.props.dispatch,this.props.invoiceId);}componentDidUpdate(prevProps){if(prevProps.invoiceId!==this.props.invoiceId){fetchInvoice(this.props.dispatch,this.props.invoiceId);}}render(){if(!this.props.invoice){returnnull;}return<h1>{invoice.number}</h1>;}}exportdefaultconnect((state)=>{return{invoices:state.invoices};})(Invoices);