Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

importing Network module for clearCookies

Tags:

react-native

I was needing to clearCookies and found a hidden/undocumented function - https://github.com/facebook/react-native/blob/26684cf3adf4094eb6c405d345a75bf8c7c0bf88/Libraries/Network/RCTNetworking.android.js

I am able to access it like this:

import RCTNetworking from 'RCTNetworking'
console.log('RCTNetworking:', RCTNetworking.clearCookies);

It works, but is it correct? Will import RCTNetworking from 'RCTNetworking' work guranteed?

I thought it would be more safe to import from NativeModules like this:

import { NativeModules } from 'react-native'
console.log('Networking:', NativeModules.Networking.clearCookies);

However this imports the whole NativeModules which has a bunch of other stuff. Wouldn't this be bad? Or does tree shakingng in production remove all the stuff I don't use from NativeModules?

Is there another way to access clearCookies? Is this documented anywhere?

like image 467
Noitidart Avatar asked Nov 08 '22 10:11

Noitidart


1 Answers

I imported RCTNetworking like this: var RCTNetworking = require("RCTNetworking"); This import is guaranteed to work on all platforms.
I couldn't find any documentation for RCTNetworking nor for the clearCookies() function

like image 178
joshkmartinez Avatar answered Nov 15 '22 13:11

joshkmartinez