I'm newer to react. I have a react/node app that shows different data on tv monitors all going to different urls. localhost/s/1... localhost/s/2, etc. We want to move to just using 1 monitor that auto updates itself. I thought we could use a redirect triggered by the timer we have running. When the redirect fires the url does change but no data updates using the new url param because we're going to the same route.
UpdateTimer = ({ time, rest }) => {
this.setState({ time, rest })
const screenNumber = this.props.match.params.id
if (rest === false && time === "0:01" && parseInt(screenNumber) < 7){
this.props.history.push(`/s/${parseInt(screenNumber)+1}`)
this.setState({ time: "1:00", rest : true })
}
}
I tried adding timestamp to the route with no effect. Reload component via <Link> in React Router
<Route path="/s/:id" component={(props) => <Screens timestamp={new Date().getTime().toString()} {...props} socket={socket} /> } />
Any suggestions for updating data with the new url param?
EDIT: here is the component code. The timer counts from 4:00 to 0:00 then 1:00 of rest where rest is true then goes back to 4:00. I need the redirect to fire where rest is false and the timer is 0:01.
componentDidMount() {
const screenNumber = this.props.match.params.id
const { socket } = this.props
socket.on('connect', () => {
socket.emit('joinRoom', 'screens')
socket.emit('initScreen', screenNumber)
})
socket.on('timer', ({ time, rest }) => this.UpdateTimer({ time, rest }))
socket.on('screenInfo', data => this.UpdateScreenInfo({ data }))
socket.on('queueInfo', data => this.UpdateQueueInfo({ data }))
socket.on('queue', ({ queue }) => this.UpdateQueue({ queue, screenNumber }))
}