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 · 3 comments
Closed

Export SitecoreContextReactContext #224

jbreuer opened this issue Jul 25, 2019 · 3 comments

Comments

@jbreuer
Copy link
Contributor

@jbreuer 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

This comment has been minimized.

Copy link
Contributor

@kamsar 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

This comment has been minimized.

Copy link
Contributor Author

@jbreuer jbreuer commented Jul 25, 2019

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

@sc-dawidrutkowski

This comment has been minimized.

Copy link
Collaborator

@sc-dawidrutkowski sc-dawidrutkowski commented Aug 9, 2019

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.