i tried using MUI CORE for first time and it’s giving me arror as i wanted to use active first rating and set value is not defined
i
JavaScript
x
28
28
1
mport './App.css';
2
import 'bootstrap/dist/css/bootstrap.min.css';
3
import Movie from './components/movie';
4
import data from './data';
5
import Rating from '@mui/material/Rating';
6
import React, { useState } from 'react';
7
8
function App() {
9
10
console.log(data)
11
return (
12
<div className="App">
13
14
<Rating
15
16
name="simple-controlled"
17
value={3}
18
onChange={(event, newValue) => {
19
setValue(newValue);
20
}}
21
/>
22
</div>
23
);
24
}
25
26
export default App;
27
28
JavaScript
1
2
1
type here
2
JavaScript
1
1
1
Advertisement
Answer
Ey!
The only thing that i can see is that you are trying to use “setValue” in the “onChange” event handler for the “Rating” component, but there is not a “setValue” defined, so maybe that’s the problem.
Here is a possible solution:
JavaScript
1
27
27
1
import './App.css';
2
import 'bootstrap/dist/css/bootstrap.min.css';
3
import Movie from './components/movie';
4
import data from './data';
5
import Rating from '@mui/material/Rating';
6
import React, { useState } from 'react';
7
8
function App() {
9
const [value, setValue] = useState(3);
10
11
console.log(data)
12
return (
13
<div className="App">
14
15
<Rating
16
name="simple-controlled"
17
value={value}
18
onChange={(event, newValue) => {
19
setValue(newValue);
20
}}
21
/>
22
</div>
23
);
24
}
25
26
export default App;
27
useState hook is used to create a state variable called “value” with an initial value of “3”. setValue function is used to update the value of the “value” state variable when “onChange” event is fired.