What I'm struggling to do is read route params inside a 'class extends React.Component'.
I have a page built like this, and it works fine (because it is as const and I can put the {route}):
const SecondPage = ({route}) => { useEffect(() => { fetch('https://myurl', { method: 'POST', headers: { Accept: 'application/json', 'Content-Type': 'application/json' }, body: JSON.stringify({ aula: route.params.paramKey //HERE WORKS FINE }) }) ...
But in another page, that looks like the code bellow, I have NO IDEA of how I can read a param passed from the previous screen inside it
class Newpage extends React.Component { constructor(props) { super(props); this.state = { isFetching: false, isLoading: null, tooltipPos: { x: 0, y: 0, visible: false, value: 0 }, data: { labels: ["", "", "", "", "", "", ""], datasets: [ { data: [0, 0, 0, 0, 0, 0, 0] } ] } }; } getApiData() { const self = this; fetch('https://anotherurl', { method: 'POST', headers: { Accept: 'application/json', 'Content-Type': 'application/json' }, body: JSON.stringify({ param: passedParam //HERE I NEED TO HAVE THE PASSED PARAM }) }) ...
https://stackoverflow.com/questions/67040840/read-route-params-inside-class-component April 11, 2021 at 10:06AM
没有评论:
发表评论