I have one common component for Success and rendering this component through navigating routes.
SuccessComponent.jsx
var pageTitle;
const SuccessComponent = (props) => {
pageTitle = props.location.state.title;
return(
<> jsx code here </>
)
}
//This title needs to be dynamic, not getting props here hence took var pageTitle but getting undefined.
let SuccessComp = withTitle({component: SuccessComponent, title: pageTitle})
export default SuccessComp;
WithTitle component is setting title through react-helmet library and updating on each screen. I need to change title on different calls of SuccessComponent. How can I achieve this?
I'm using SuccessComponent as below.
MyComponent.jsx
export default MyComponent = () => {
const onSubmit = () => {
props.history.push({pathname:'/success',state:{title: 'my comp'})
}
return(
<> jsx code here </>
)
}
MyComponent1.jsx
export default MyComponent1 = () => {
const onSubmit = () => {
props.history.push({pathname:'/success',state:{title: 'my comp 1'})
}
return(
<> jsx code here </>
)
}
withTitle.jsx
export default function withTitle({component: Component, title}){
return function title(props){
(
<>
<Helmet>
<title>{title}</title>
</Helmet>
<Component {...props} />
</>
)
}
}