Skip to content
Advertisement

React window is not closing when the user clicks the button

I open a React web app like this in my index.js file:

ReactDOM.render(
    <React.Fragment>
        <Review pplNum={num} />
    </React.Fragment>,
    document.getElementById('root')
)

I then want the user to be able to close it, but close button doesn’t work.

Here is the Review component:

import React, { useEffect } from "react";
import axios from 'axios';

const Review = ({ pplNum }) => {
    axios.put('/books/reviews/' + pplNum)
        .then(res => console.log(res.data));
    return (
        <div>
            <div>Thank you for the review</div>
            <div><a href="javascript:window.close">Click here to close</a> this window</div>
        </div>
    );
}

export default Review;

When I click it to close, nothing happens.

Is there something I am not doing correctly?

Thanks!

Advertisement

Answer

You’re not calling it as a function:

<a href="javascript:window.close()">Click here to close</a>
Advertisement