Как использовать некоторые реквизиты на других компонентах Reactjs

Если вы получаете эту ошибку из MiniProfiler в MVC, вы можете увеличить значение, установив свойство MiniProfiler.Settings.MaxJsonResponseSize на нужное значение. По умолчанию этот инструмент игнорирует значение, установленное в config.

MiniProfiler.Settings.MaxJsonResponseSize = 104857600;

Предоставлено mvc-mini-profiler .

-2
задан Sadiq Mustapha Aji 16 January 2019 в 12:46
поделиться

1 ответ

Поскольку вы упомянули react-router | react-router-dom в v4, вы можете сделать это одним из следующих способов:

A

  1. Заменить на [117 ]
<Link
  className="btn btn-primary" // some bootstrap class 
  to={{
    pathname: "/watch",
    state: { posterId: poster.id } // I am assuming  post has id
  }}
/>
  1. в WatchComponent
class WatchComponent extends React.Component {
 componentDidMount() {
   const { posterId } = this.props.location.state;
   //make ajax request to the server and get poster details 
   //promise resolve, set response into state 
   // this.setState({ poster: res.json()})

 }
 render() {
   const { poster } = this.state;
   return (
     // render poster details here.
   )


 }
}

Или Вы можете просто сделать это

<Link
  className="btn btn-primary" // some bootstrap class 
  to={`/watch/${posterId}`} // provided that Route of WatchComponent is defined as (URL parameter) <Route path="watch/:posterId" component={WatchComponent} />
/>

затем в WatchComponent вы делаете

class WatchComponent extends React.Component {
 componentDidMount() {
   const { posterId } = this.props.macth.params;
   //make ajax request to the server and get poster details 
   //promise resolve, set response into state 
   // this.setState({ poster: res.json()})

 }
 render() {
   const { poster } = this.state;
   return (
     // render poster details here.
   )


 }
}
0
ответ дан tbuglc 16 January 2019 в 12:46
поделиться
Другие вопросы по тегам:

Похожие вопросы: