Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export SitecoreContextReactContext #224

Closed
jbreuer opened this issue Jul 25, 2019 · 8 comments
Closed

Export SitecoreContextReactContext #224

jbreuer opened this issue Jul 25, 2019 · 8 comments

Comments

@jbreuer
Copy link
Contributor

jbreuer commented Jul 25, 2019

Currently it's possible to get the Sitecore Context by using withSitecoreContext(): https://jss.sitecore.com/docs/client-frameworks/react/sample-app#sitecore-context-access

This works in most situations, but sometimes you don't want to wrap your component with this HOC. For example when you are creating a custom hook.

By exporting SitecoreContextReactContext you can use the new useContext hook: https://reactjs.org/docs/hooks-reference.html#usecontext

Then the following should work:

import { useContext } from 'react';
import { SitecoreContextReactContext } from '@sitecore-jss/sitecore-jss-react';
const sitecoreContextFactory = useContext(SitecoreContextReactContext);
const pageEditing = sitecoreContextFactory.getSitecoreContext().pageEditing;
jbreuer added a commit to jbreuer/jss that referenced this issue Jul 25, 2019
@kamsar
Copy link
Contributor

kamsar commented Jul 25, 2019

Longer term would it be a better solution to export a custom hook to expose this that wrapped useContext?

@jbreuer
Copy link
Contributor Author

jbreuer commented Jul 25, 2019

Yes for the longer term a custom hook would be better.

@sc-dawidrutkowski
Copy link
Collaborator

I did some basic tests and that change looks valid. The associated pull request has been merged.

sc-dawidrutkowski added a commit that referenced this issue Dec 3, 2019
* Added support for TypeScript when 'jss build'ing

* Type-hint field value.

* Update dataModels.ts

* Move type hint to Field.

* Type-lock return value when defaultValue provided.

* Fix to copy host style attribute to its children dynamic components

* changed spacing

* updates for ssr

* Add loader for lazy loaded components

* Add some documentation

* Placeholder loading component

* Use ng-template instead of ng-content

* Fix typo

* Export SitecoreContextReactContext

See #224

* WIP: simple http listener that accepts JSS view engine args, performs SSR, and returns result to caller.

* Moved JSS rendering host to separate package.

* SUGCON demo prep

* Removed unnecessary console.log statements from htmlTemplateFactory.js

* Changed `start:http-renderer` script name to `start:rendering-host`

* Demo content for content block component.

* Changed `sc_renderengineurl` querystring key to the CORRECT `sc_httprenderengineurl`. doh, smh.

* Incorporating `defaultAppInvocationInfoResolver` into the renderingHostServer startup script.

* removed static `jss` subdomain for ngrok tunnel

* Fixing tests

* #61 Nested component definitions via Item Link returns only IDs

* Upgrade dependencies with critical and high security issues (#252)

Upgrade dependencies

* Upgrade cypress

* downgrade dependency version

* Feature/356383 (#256)

Upgrade sitecore-jss-react package dependencies

* remove InferProps (#259)

remove InferProps

* Feature/356379 (#265)

* update react sample dependencies

* update dependencies and fix ts errors (#266)

Upgrade Vue package dependencies

* #267 Error in description of one of methods of Manifest interface

* Upgrade Vue sample (#269)

Upgrade Vue sample

* Feature/356380: Update Angular

* Upgrade jss-angular and jss-angular-schematics and jss-sample-app

* Feature/356378 (#272) Upgrade CLI Packages

Upgrade CLI Packages

* Use Object.entries instead of Object.keys (#274)

Use Object.entries instead of Object.keys

* mediaApi.updateImageUrl loses revision querystring (#275)

mediaApi.updateImageUrl loses revision querystring

* DevTools loading hidden files and crashing (#276)

* Feature/356373 (#273) Node Proxy: CURL URL -IL returns 500 OK

Node Proxy: CURL URL -IL returns 500 OK

* change logo (#279)

change logo

* upgrade react-native sample (#282)

upgrade react-native sample

* [React-Native] Extend Image component to render svg images (#283)

* add react-native-svg to sample app

* update react-native package-lock

* add react-native-svg to sitecore-jss-react-native

* #348713Explicitly state that field names are not affected by the serialization configuration on Layout Service (#284)

* #348713 Explicitly state that field names are not affected by the serialization configuration on Layout Service

* #348713 Update

* Extended a CD server setup instructions (#286)

* React native sample app (#291)

React native sample app
juliavanmourik pushed a commit to aon-nl/sitecore-jss-manifest that referenced this issue Nov 17, 2020
* Added support for TypeScript when 'jss build'ing

* Type-hint field value.

* Update dataModels.ts

* Move type hint to Field.

* Type-lock return value when defaultValue provided.

* Fix to copy host style attribute to its children dynamic components

* changed spacing

* updates for ssr

* Add loader for lazy loaded components

* Add some documentation

* Placeholder loading component

* Use ng-template instead of ng-content

* Fix typo

* Export SitecoreContextReactContext

See Sitecore/jss#224

* WIP: simple http listener that accepts JSS view engine args, performs SSR, and returns result to caller.

* Moved JSS rendering host to separate package.

* SUGCON demo prep

* Removed unnecessary console.log statements from htmlTemplateFactory.js

* Changed `start:http-renderer` script name to `start:rendering-host`

* Demo content for content block component.

* Changed `sc_renderengineurl` querystring key to the CORRECT `sc_httprenderengineurl`. doh, smh.

* Incorporating `defaultAppInvocationInfoResolver` into the renderingHostServer startup script.

* removed static `jss` subdomain for ngrok tunnel

* Fixing tests

* #61 Nested component definitions via Item Link returns only IDs

* Upgrade dependencies with critical and high security issues (#252)

Upgrade dependencies

* Upgrade cypress

* downgrade dependency version

* Feature/356383 (#256)

Upgrade sitecore-jss-react package dependencies

* remove InferProps (#259)

remove InferProps

* Feature/356379 (#265)

* update react sample dependencies

* update dependencies and fix ts errors (#266)

Upgrade Vue package dependencies

* #267 Error in description of one of methods of Manifest interface

* Upgrade Vue sample (#269)

Upgrade Vue sample

* Feature/356380: Update Angular

* Upgrade jss-angular and jss-angular-schematics and jss-sample-app

* Feature/356378 (#272) Upgrade CLI Packages

Upgrade CLI Packages

* Use Object.entries instead of Object.keys (#274)

Use Object.entries instead of Object.keys

* mediaApi.updateImageUrl loses revision querystring (#275)

mediaApi.updateImageUrl loses revision querystring

* DevTools loading hidden files and crashing (#276)

* Feature/356373 (#273) Node Proxy: CURL URL -IL returns 500 OK

Node Proxy: CURL URL -IL returns 500 OK

* change logo (#279)

change logo

* upgrade react-native sample (#282)

upgrade react-native sample

* [React-Native] Extend Image component to render svg images (#283)

* add react-native-svg to sample app

* update react-native package-lock

* add react-native-svg to sitecore-jss-react-native

* #348713Explicitly state that field names are not affected by the serialization configuration on Layout Service (#284)

* #348713 Explicitly state that field names are not affected by the serialization configuration on Layout Service

* #348713 Update

* Extended a CD server setup instructions (#286)

* React native sample app (#291)

React native sample app
@peterswallow
Copy link

Any idea when or if this will be released?

@ambrauer
Copy link
Contributor

@peterswallow This has been released since JSS 12.0.0, as well as a hook useSitecoreContext introduced with JSS 16.0.0. So you can now do something like:

import { useSitecoreContext } from '@sitecore-jss/sitecore-jss-react';
const { sitecoreContext } = useSitecoreContext();
const pageEditing = sitecoreContext.pageEditing;

@peterswallow
Copy link

@ambrauer I'm using 12.0.0 but SitecoreContextReactContext doesn't appear to be exported...unless I'm looking in the wrong place.

@ambrauer
Copy link
Contributor

@peterswallow How are you attempting to use? e.g. import { SitecoreContextReactContext } from '@sitecore-jss/sitecore-jss-react'; should work. See export in version 12.0.0 here.

@kevinolivar
Copy link

Hi there,

I am using withSitecoreContext({ updatable: true }) in one of my UI components. The whole app is wrapped within a .

However, when I navigate around the context seems not being updated...only when I refresh the page.
I also tried using useSitecoreContext. Same result.

Idea?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants