1

Object _spPageContextInfo is available in my DOM tree. How to get his properties with react.JS ?

4

I too get same problem, and i resolved it by using the SPComponentLoader.loadScript, please refer below code snippet

SPComponentLoader.loadScript(siteColUrl + '/_layouts/15/init.js', {
    globalExportsName: '$_global_init'
})
.then((): Promise<{}> => {
    return SPComponentLoader.loadScript(siteColUrl + '/_layouts/15/MicrosoftAjax.js', {
    globalExportsName: 'Sys'
});})
.then((): Promise<{}> => {
    return SPComponentLoader.loadScript(siteColUrl + '/_layouts/15/SP.Runtime.js', {
    globalExportsName: 'SP'
});})
.then((): Promise<{}> => {
    return SPComponentLoader.loadScript(siteColUrl + '/_layouts/15/SP.js', {
    globalExportsName: 'SP'
});})
.then((): void => {
    let spContext: SP.ClientContext =new SP.ClientContext(siteColUrl);
    //place your logic here.
});

Make sure to add the microsoft-ajax and sharepoint in your tsconfig.json file like below,

"types": [     
  "webpack-env",
  "microsoft-ajax",
  "sharepoint"
]

Also, add the below packages in your package.json file and make sure to restore the npm packages.

"@types/microsoft-ajax": "0.0.33",
"@types/mocha": ">=2.2.33 <2.6.0",
"@types/sharepoint": "^2013.1.6",

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.