react-native-nfc-manager
react-native-nfc-manager copied to clipboard
Update readme
Changes
-
Update basic usage example code
-
Fixed some typos
-
The other example code such as
registerTagEvent
,NDEF-Writing
andMifare Ultralight
might be improved in future
It seems that the code snippet want to demonstrate how to start NFC scanning automatically without pressing a button, but I think it will be easier to understand if the whole process starts from a button press.
In such a case, we can avoid extra useEffect
hook and focus our code on NFC
part, since it serves as the most basic example for the library.
About the scan without button press
scenario, I think it might deserve another README section since people often ask about it.
So it might be better to move this part to the new MD file and give the link in the original README right? Or I can add new section in README
Yes, I think this will be great!
Ok I'll mark this PR as a draft till I have done with this part
Both new MD or new section are good to me
I'd prefer new section
It seems that the code snippet wants to demonstrate how to start NFC scanning automatically without pressing a button, but I think it will be easier to understand if the whole process starts from a button press.
In such a case, we can avoid the extra
useEffect
hook and focus our code on theNFC
part, since it serves as the most basic example for the library.About the
scan without button press
scenario, I think it might deserve another README section since people often ask about it.
About extra useEffect
, did you mean the following code about initializing nfcManager?
I implement nfcManager.start()
this way to prevent multi time initalize, or there's might be better way to implement this
// Initialize the NFC manager (This will run only once)
useEffect(() => {
nfcManager.isSupported().then(supported => {
if (supported) {
nfcManager.start();
} else {
setNfcData('NFC not supported');
}
})
}, [])
I understand you're using a standard zero deps
pattern to initialize the native module.
The problem is inside the next hook:
// Listen to NFC events (This will run every-time after nfcData changes)
useEffect(() => {
getNFCInfo();
}, [nfcData])
Two points here:
- Once
nfcData
changed, thegetNFCInfo()
will be called, which is generally not desired. - It cannot garuantee native
NfcManager.start()
is successfully called
And one extra point to be aware is that: NfcManager.start()
is also async
call, so there might be a chance that you trigger the NFC scan before the native module is fully initialized.
I understand you're using a standard
zero deps
pattern to initialize the native module.The problem is inside the next hook:
// Listen to NFC events (This will run every-time after nfcData changes) useEffect(() => { getNFCInfo(); }, [nfcData])
Two points here:
- Once
nfcData
changed, thegetNFCInfo()
will be called, which is generally not desired.- It cannot garuantee native
NfcManager.start()
is successfully calledAnd one extra point to be aware is that:
NfcManager.start()
is alsoasync
call, so there might be a chance that you trigger the NFC scan before the native module is fully initialized.
I got it, thanks for your feedback, appreciated :)
This PR is stale because it has been open 45 days with no activity. Remove stale label or comment or this will be closed in 10 days.
This PR was closed because it has been stalled for 10 days with no activity.