Platform is a read only object
See original GitHub issueDescription
Seems like Platform object from react-native is a read only object, and mocking the functions like Version isn’t possible.
After doing Object.defineProperty(Platform, "Version", { writable: true }), I was able to update the object. Is this intentional?
Reproduction Steps and Sample Code
Example:
Platform.Version = 24
Solution
Haven’t looked too deep into, but if it’s something that needs to change I’d like to do a PR for it
Additional Information
- React Native version: 0.40
- Platform: both
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
readonly keyword - C# Reference - Microsoft Learn
The readonly keyword is a modifier that can be used in four contexts: ... is a readonly reference type must always refer to...
Read more >ReadOnly (Property Keyword) - InterSystems Documentation
ReadOnly - Specifies that a property is read-only, which limits the number of ways its value can be set.
Read more >cannot assign to read-only property of object - Stack Overflow
the first approach you are mutating action.payload directly since you are not creating a copy to newItem but passing the same reference.
Read more >Read-only object cache - Optimizely
Most APIs in Optimizely CMS return read-only instances of objects, such as IContentLoader.Get<TContentData> which return a read-only IContent instance.
Read more >Read-Only Mode - Salesforce Help
What to Expect in Read-Only Mode · Add, edit, or delete data · Perform any actions in Salesforce that modify your Salesforce data....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

What about it? It’s not really different from
Version.if you really wanted it. What do you propose, a PR that freezes entire
Platformobject? I don’t see a standard in this code base that freezes the public APIs (for example all react-native keys are also writable), but then again I am not a contributor to this project so I’ll let FB engineers comment for it.Hi there! This issue is being closed because it has been inactive for a while. Maybe the issue has been fixed in a recent release, or perhaps it is not affecting a lot of people. Either way, we’re automatically closing issues after a period of inactivity. Please do not take it personally!
If you think this issue should definitely remain open, please let us know. The following information is helpful when it comes to determining if the issue should be re-opened:
If you would like to work on a patch to fix the issue, contributions are very welcome! Read through the contribution guide, and feel free to hop into #react-native if you need help planning your contribution.