when I want to access props that , are passing through in my App.js component, in StreamEdit component it`s empty.
it must have match.params.id
import {Route ,Routes } from 'react-router-dom';
import { unstable_HistoryRouter as HistoryRouter } from "react-router-dom";
import './App.css';
//,BrowserRouter as Router
const App =() =>{
return(
<div id='app_div'>
<HistoryRouter history={history}>
<Header/>
<Routes>
<Route path='/' exact Component={StreamList} />
<Route path='/streams/new' Component={StreamCreate} />
<Route path='/streams/edit/:id' Component={StreamEdit} />
<Route path='/streams/delete' Component={StreamDelete} />
<Route path='/streams/show' Component={StreamShow} />
</Routes>
</HistoryRouter>
</div>
);
};
export default App;
import React from "react";
import { connect } from "react-redux";
import {fetchStream} from '../../actions';
class StreamEdit extends React.Component{
componentDidMount(){
this.props.fetchStream(this.props.match.params.id);
}
}
const mapStateToProps = (state ,ownProps) =>{
console.log(ownProps)
return {stream : state.streams};
}
export default connect(mapStateToProps ,{fetchStream}) (StreamEdit);
I expect to achieve some data from this.props.match.params.id
New contributor
saba is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.