62 }
63 };
64 // renderAlert is a function that is used to render alerts if needed.
65 const renderAlert = () => { 66 if (status.success.current === true) {
67 return (
68 <Alert status="success">
26
27// Dashboard page
28const Dashboard = () => {
29 const fetchKeypairs = async () => {30 try {
31 const options = { withCredentials: true };
32 const response = await fetchData(
34 error: useRef(false),
35 };
36
37 const renderAlert = () => { 38 if (status.success.current === true) {
39 return (
40 <Alert status="success">
Any code paths that do not have explicit returns will return undefined
.
It is recommended to replace any implicit dead-ends that return undefined
with a return null
statement.
As a convention, undefined
signals that an unexpected value has been produced as the
result of a logical error in the program.
A null
return, on the other hand, signals that the input to a function was incorrect,
or a value was 'not found'.
Having this distinction in code helps you figure out if something was caused because of a logical error, or malformed input to a function call.
function getUser(name) {
if (userExists(name)) {
return userDb.get(name);
}
// whoops! Implicit undefined return
}
function readFile(fileName) {
if (fs.existsSync(fileName)) {
return fs.readFileSync(fileName, 'utf-8');
}
return; // Implicit undefined return.
}
function getUser(name) {
if (userExists(name)) {
return userDb.get(name);
}
// `null` indicates there is no such user.
return null;
}
function readFile(fileName) {
if (fs.existsSync(fileName)) {
return fs.readFileSync(fileName, 'utf-8');
}
// `null` indicates there is no such file.
return null;
}