React Material UI Label Overlaps with Text

前端 未结 5 1712
滥情空心
滥情空心 2021-02-12 18:59

I\'m using Material UI in a React application and trying to implement an entity update page. In this, we would need to set the exiting values of the entity to let the user updat

5条回答
  •  抹茶落季
    2021-02-12 19:19

    I had the same issue; however it was inconsistent - meaning sometimes I have the labels displayed properly and sometimes overlapped

    I tried the following and it worked fine. Basically the form is first rendered empty without data; then the useEffect was fetching the data and populating the data. I set a isLoading state variable - this will be initially set to true and set to false after the data is fetched by API.

    Display all the data only after isLoading is false - this works well.

    Code Snippet

    export default function UserProfile(props) {
    const classes = useStyles();
    const [user, setUser] = React.useState({});
    const [isLoading, setIsLoading] = React.useState(true);
    
    const getUser = async () => {
        const requestOptions = {
            method: 'GET',
            cache: 'no-cache',
            headers: { 
                'Content-Type': 'application/json',
            },
            redirect: 'follow',
            referrerPolicy: 'no-referrer',            
        };
    
        const response = await axios.request(
            "/api/userprofile",
            requestOptions
        );
    
        const responseData = await response.data;
        
        setUser( responseData.userProfile );
        setIsLoading(false);
    }
    
    React.useEffect(() =>{
        getUser();
        console.log(user);
    })
    
    return(
        
    <>{ isLoading ?
    :
    User Profile
    }
    );

    }

提交回复
热议问题