Open dwijesingheWR opened 5 years ago
@dwijesingheWR doing files[filenameNoDot] = file;
is not iterable by the normal javascript array methods . For instancefiles.map
or files.forEach
would produce an empty array which is my guess why it wipes it out completely. try asArray : false
@qwales1 Thanks for getting back to me. I tried setting asArray
to both true and false, I've also tried changing files
to an object instead of an array, neither seems to be helping. Without syncState, either an object or an array works fine, with syncState added, setState simply will not update files
(although checking in the debugger, I can see that the files
array created in addFile
updates appropriately). Any thoughts on why this might be?
@dwijesingheWR is the database getting updated at all?
Yes I have another syncState call watching a different state property (data) and all changes to data, which is a fairly simple object, persist to Firebase without issue. In addition if I change
files[filenameNoDot] = file;
to
files[filenameNoDot] = 42;
the files
array gets updated in Firebase. It seems to be a specific issue with File objects.
@dwijesingheWR oh yeah now i see that sorry. I'm not sure about storing files in firebase directly. base64 encoding them looks like it works from a quick search but I know they have Firebase Storage now for files
Hi,
My React app allows the user to select one or more images, renders a preview of the selected images, then allows them to submit the image up to the server. Until they are sent to the server, images are store in the App state as an associative array
{files: []}
. The code was working until I started using Firebase to persist the App state and added asyncState
call forfiles
. After adding the syncState call myaddFile
function can no longer update the App statefiles
array. I tested, and simply removing the syncState code for files restores full functionality to the app. Am I doing something wrong in terms of how I'm using syncState here? I have another syncState call on separate App data and it works without issue.This is the code from my FileSelector component:
And the code for addFile (coded in a parent component and passed via props)
Finally my componentDidMount method which has the syncState code