score:1
I've added this to my App and it seems to receive changes when routes change. More reference here
class App extends React.Component {
...
getInitialState() {
return {
lang: 'en' // default
};
}
componentWillReceiveProps(props) {
console.log('location: ', props.location.pathname);
var newLang = props.location.pathname.split('/').shift();
if(this.state.lang !== newLang) {
this.setState({lang: newLang});
}
}
render() {
const lang = this.state.lang;
return (
<AboutPage language={lang} />
<Support language={lang} />
);
}
}
If this doesn't work, you can also look into how two components talk to each other
Source: stackoverflow.com
Related Query
- How to update state after React Router changes automatically?
- React how to update ui after every loop iteration which changes state array?
- How to update the router state on history.replace in react router?
- How to update React component after changing state through redux?
- How to test state update and component rerender after async call in react
- React - How to Update State After AJAX Request
- How does React update a component and its children after a state change?
- React doesn't update component after state changes
- react router v6 won't switch to Home Page after Login Page: Warning: Can't perform a React state update on an unmounted component
- React state created with useState doesn't update automatically when my API changes
- How to refresh components when parent state changes in react when using react router
- How to update the React State only after a return from API called is completed
- How to update items in a component after state changes
- REACT + FIRESTORE : Listen to changes in firebase collection in a react component to automatically update the react state
- How do I update state when a window variable changes in react
- Update state when page changes in React Router
- React JS (Form Update Not Working) - How to set state immediately after getting data from API using mapDispatchToProps?
- How to instantly update react state after replacing the value from array
- React + TypeScript - how to update state with single object with a "dynamic" set of changes
- React with Hooks: how to correctly update state after a click event?
- How we can update the state of button to logout after successfull login in react redux
- How to set the initial state value after fetching data to update a form in react
- How to update nested state properties in React
- React router, how to restore state after browser back button?
- React router and this.props.children - how to pass state to this.props.children
- How to update array state in react native?
- How to update react state without re-rendering component?
- React hooks: How do I update state on a nested object with useState()?
- Redux router - how to replay state after refresh?
- React router v4 - How do you access the state that is passed via Redirect?
More Query from same tag
- this.props working for one func and don't work for another React-Redux
- What is the idiomatic way to create styles for a Reason-React component that depend on props?
- Toggle click on a mapped data React JS
- Dynamic tag incorrect casing
- React callbackRef.current is not a function
- Disable all dates before today - Ant Design Calendar
- How to filter a list according to Slider selection?
- Code not running inside a React component
- Return only once but returning multiple times
- Reactjs ES6 Access function outside of class
- React ajax call when button onClick event using hooks
- How to style {Switch} component from react-router-dom? I tried wrapping it with <div> and does not work
- Percent in url next js
- Stripe redirectToCheckout - "TypeError: stripe.redirectToCheckout is not a function"
- Order of setState
- click not working if parsed through reactjs
- Highcharts custom data for map in React TypeScript?
- How do I force Update my components in my react code to toggle dark theme to light theme
- Loading React Sidebar in Parent Component when Child Component Loads
- MUI5 not working with jest - SyntaxError: Cannot use import statement outside a module
- Dynamic Page according to React-Redux state not updating rendered data
- How to adjust the component height with browser height?
- React Router NavLink Active
- Debounce not working if state is also modified in function
- Javascript : How to select elements within one instance of a react class?
- How to routing between packages in workspace using react-router?
- Send request depending on a condition from a previous request
- Graphql Mutation error - errors: [{message: "Variable "$firstName" of required type "String!" was not provided.",…}]
- React not render div into li tag
- using multiple curly braces in React