- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2024 02:38 AM - edited 01-20-2024 02:38 AM
Hi,
I'm looking at the documentation and it talks about setInitialState: https://developer.servicenow.com/dev.do#!/reference/next-experience/vancouver/ui-framework/main-conc...
However the examples are using initialState: https://github.com/ServiceNowDevProgram/now-experience-component-examples/blob/quebec/src/checklist-...
initialState is working in my code, setInitialState is not.
What is the difference between the two? Is setInitialState deprecated? If yes why is the documentation not updated?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2024 11:01 AM
Nevermind I got it the other way around, I was actually on a lower version...
@Servicenow/ui-core and @Servicenow/ui-renderer-snabbdom were installed as version "quebec" in my project folder. I am not sure why it is taking this version as I did npm install just today... Anyway I installed the latest version listed on npmjs (24.1.1) for both, which fixed this problem and now the setInitialState is recognized and is working properly.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2024 07:14 AM
Hi,
For me, both intialState & setInitialState are working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2024 09:37 AM - edited 01-20-2024 09:43 AM
I am not sure, I set the exact same code and it does not work
Is this a version difference? What versions are you using in your dependencies?
I also get an error in the browser console when using setInitialState but have no idea what this means:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2024 10:30 AM
There is a validation function that validates the config object that you pass into createCustomElement(). Basically if you try to pass gibberish that is not recognized then it will throw this error, so setInitialState in my environment is for some reason not a valid/recognized property. Maybe I'm on a newer version.
But then let me rephrase this question:
- Naturally you would many times have to base your initial state on the received props... "initialState" is just a regular object so in there I do not have access to properties. That is why I wanted to use setInitialState() because there I can go over all the properties and set up my component's initial state, however as it is not working, what would be the best way to do this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2024 11:01 AM
Nevermind I got it the other way around, I was actually on a lower version...
@Servicenow/ui-core and @Servicenow/ui-renderer-snabbdom were installed as version "quebec" in my project folder. I am not sure why it is taking this version as I did npm install just today... Anyway I installed the latest version listed on npmjs (24.1.1) for both, which fixed this problem and now the setInitialState is recognized and is working properly.