r/reactjs • • Feb 01 '19

Needs Help Beginner's Thread / Easy Questions (February 2019)

🎊 This month we celebrate the official release of Hooks! 🎊

New month, new thread 😎 - January 2019 and December 2018 here.

Got questions about React or anything else in its ecosystem? Stuck making progress on your app? Ask away! We’re a friendly bunch.

No question is too simple. πŸ€”

Last month this thread reached over 500 comments! Thank you all for contributing questions and answers! Keep em coming.


πŸ†˜ Want Help with your Code? πŸ†˜

  • Improve your chances by putting a minimal example to either JSFiddle or Code Sandbox. Describe what you want it to do, and things you've tried. Don't just post big blocks of code!
  • Pay it forward! Answer questions even if there is already an answer - multiple perspectives can be very helpful to beginners. Also there's no quicker way to learn than being wrong on the Internet.

Have a question regarding code / repository organization?

It's most likely answered within this tweet.


New to React?

πŸ†“ Here are great, free resources! πŸ†“


Any ideas/suggestions to improve this thread - feel free to comment here or ping /u/timmonsjg :)

35 Upvotes

484 comments sorted by

View all comments

Show parent comment

1

u/TheNobleLad Feb 21 '19

Thank you for replying! That defo gave me a better insight and a relief knowing it is possible (as frankly enough, I haven't found any much plausible solutions before it). I think it's ideal to start with the function captureShot() considering const screenshot = this.webcam.getScreenshot(); gives a base64 format and it's just what I need for now. As for the function captureShot() in reactJS, any tips on getting rid of the FileReader() and replacing it with an already-captured, encoded image instead?

1

u/timmonsjg Feb 21 '19

As for the function captureShot() in reactJS, any tips on getting rid of the FileReader() and replacing it with an already-captured, encoded image instead?

hmm, not entirely sure what you're asking. Do you mean having a default image for when users don't use their webcam?

You could store a base64 encoded image in your project and import it where needed.

const defaultEncodedImage = "data:image/png;base64, ....."

That really sucks, but it would be easiest.

1

u/TheNobleLad Feb 22 '19

Kinda similar to what I was looking for. I realized that const screenshot = this.webcam.getScreenshot(); already has the "data:image/jpeg..". I just needed the image in raw base64 for request and response so I did base64Image = screenshot.replace("data:image/jpeg;base64,","");. Thanks for the help!