score:0
- first of all, look into functional components.
- a route component expects a component, not logic. handle the actual variable change in that component or elsewhere via react-router's uselocation hook.
what you're attempting to do is to change the state of the variable. cue react's usestate and useeffect hooks (the component needs to be a functional component for hooks to work).
first import the hook:
import { usestate } from 'react';
then, in your case:
const [category, setcategory] = usestate('about') // initial value
and when you need to update it:
setcategory('science') // new value
Source: stackoverflow.com
Related Query
- Set local variable in method inside the html in reactjs
- ReactJS - Is there a way to trigger a method by pressing the 'Enter' key inside <input/>?
- Is it possible declaring a variable inside the class and outside the method
- How to loop inside a react const variable in the render method
- How to call the method inside the function (Clicking the a href to logout) using ReactJS
- ReactJS for loop create buttons and set variable according to the integer in the loop
- How to Set the response to a state by using this.setState inside a componentDidMount() method
- React - How to use the current state value as a variable so i can set as a index inside an array
- How to set a local variable without using useState in ReactJs
- How to store the return value of a function inside a variable in reactJS
- Iterate the items of array & null check inside a method call in Reactjs
- useState set method inside useEffect hook not updating till refreching the page
- Inside Redux's reducer, can I set a variable in the global (module) scope?
- Event Listener Callback Fires Immediately When Set Inside The Callback of Another Event Listener. ReactJS
- Access constructor variables inside the render method - Reactjs
- How to set the value of a checkbox inside a form in reactjs
- making set method of useState hook to wait for the variable update
- UseState called by UseEffect doesn't update the variable using the Set method
- State set method did not effect the main object - ReactJS
- How to set a method inside one onClick method In ReactJS to finish execution after API call?
- How to change the order of html elements inside ReactJS return function dynamically?
- The useState set method is not reflecting a change immediately
- ReactJS lifecycle method inside a function Component
- Rendering React components with promises inside the render method
- ReactJS State and Local Variable
- HTML + React: Radio button stuck on the one initially set as "checked"
- HTML drag/drop - how to set the filename of an *outgoing* drag (to desktop)
- Reactjs Warning: input is a void element tag and must not have `children` or use `props.dangerouslySetInnerHTML`. Check the render method of null
- Reactjs redux: Fetch PUT method sending only an OPTIONS method, even when the status is 200
- Why are HTML attributes set differently into the DOM?
More Query from same tag
- how to submit form data as "create" api method in ReactJS?
- Favorites showing on all users, not the specific one a user favorites
- Change style of styled component for selected Item
- How to show svg icon instead of mouse cursor in react js?
- how can I store and access data attributes on elements like select options in React
- Index Item of array not getting deleted
- How to set up Google Analytics for React-Router?
- Promise<UserCredential> is not assignable to type
- Flow: cant create react component that takes a generic or an object
- Npm @babel/types error in react typescript
- Is there a way to bind the selected date in a calendar date picker to a variable that can be accessed by another file?
- Typescript and react - Object is possibly 'null'
- Call the function and get method after receiving the data in componentDidMount()
- How to check file extension using React
- How to Add multiple Tracking ID for Google Analytics in Gatsby.js?
- JSON.Stringify | Output the result on the screen with quote tags ''
- React: how to pass props from child to parent to another child?
- How to fix material-kit-react 'module not found: webpack loader error'
- Prooblem on select in react
- Collapse React-Bootstrap Accordion from Within Accordion.Collapse component
- Testing React component -> setInterval
- Formik FieldArray Validation not Validating
- Isomorphic React.js & iso-http
- React/Express - required props 'undefined' in match/RouterContext
- How to delete an entry from a Record in typescript,based on the Id
- How to refresh the data component on form submit in React?
- How to covert object array to Array List using for loop
- Hashes do not work because of what appears to be a time delay
- Profiling heapdumps in Chrome Developer Tools (memory leak)
- How to add a header into post API using axios in react?