admin管理员组文章数量:1312927
I am following Colt Steele's React course. Sadly, the course is outdated so I chose to migrate to the latest versions of libraries myself.
Coming to the point, I am now facing this error where I am not able to extract URL params using the useParams hook in my functional ponent. I am pasting my code below for the munity to check.
App.js
import Palette from './Palette';
import seedPalettes from './assets/seedPalettes'
import './css/App.css'
import { generatePalette } from './assets/colorHelpers';
import { Routes, Route, Link, useParams } from 'react-router-dom';
function App() {
const { id } = useParams()
const findPalette = id => {
return seedPalettes.find(function (palette) {
return palette.id == id;
})
}
console.log(id);
return (
<div className='App'>
<Routes>
<Route path='/' element={<h1>Wele Home</h1>} />
<Route path='/palette/:id' element={<Palette palette={generatePalette(findPalette(id))} />} />
</Routes>
{/* <Link to='/palette'>See Palette</Link> */}
{/* <Palette palette={generatePalette(seedPalettes[4])} /> */}
</div>
);
}
export default App;
seedPalettes.js
export default [
{
paletteName: "Material UI Colors",
id: "material-ui-colors",
emoji: "
本文标签:
javascriptGet id using useParams hook in functional componentreact router dom v6Stack Overflow
版权声明:本文标题:javascript - Get id using useParams hook in functional component - react router dom v6 - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人,
转载请联系作者并注明出处:http://www.betaflare.com/web/1741906422a2404171.html,
本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论