I learned React and JavaScript and now I can't get this ternary operation to work
In the code below the return { getData };
should return just an:
const data = [
{ name: 'name', type: 'someType' },
{ name: 'name', type: 'someType' },
];
populated with the liveFile
values but I don't understand the syntax can someone explain?
import React, { useEffect, useState } from 'react';
import moment from 'moment';
import { withFirebase } from '../../../../../firebase';
import * as FIRESTORE from '../../../../../constants/firestore';
const File = ({ file, firebase }) => {
const classes = useStyles();
const [liveFile, setFile] = useState();
const [error, setError] = useState();
useEffect(() => {
firebase.db
.collection(FIRESTORE.USER_TEMP_FILES)
.doc(firebase.auth.currentUser.uid)
.collection(FIRESTORE.EDIT_FILES)
.doc(file.file.name)
.get()
.then(item => {
let fileItem;
if (item.exists) {
setError(null);
fileItem = {
...item.data(),
name: file.file.name,
path: file.file.path,
size: file.filesize,
type: file.file.type,
lastModifiedDate: file.file.lastModified,
file: file.file, // the file Blob
};
setFile(fileItem);
} else {
fileItem = {
title: '',
description: '',
name: file.file.name,
path: file.file.path,
size: file.filesize,
type: file.file.type,
lastModifiedDate: file.file.lastModified,
file: file.file, // the file Blob
};
setFile(fileItem);
setError('Could not fetch data');
}
})
.catch(err => setError(err));
}, [file.file.name]);
function getData() {
return
{liveFile ? (
{ name: liveFile.name, type: liveFile.type }
) : (
{ name: 'loading..' }
)}
};
}
return { getData };
};
export default withFirebase(File);