@@ -185,43 +185,60 @@ You can also use the `TaxonomyTree` control separately to just render a stand-al
185185 Initialize the taxonomy service and state, load basic info from term store and display the ` TaxonomyTree ` component.
186186
187187``` TypeScript
188- const taxonomyService = new SPTaxonomyService (props .context );
189- const [terms, setTerms] = React .useState <ITermInfo []>([]);
190- const [currentTermStoreInfo, setCurrentTermStoreInfo] = React .useState <ITermStoreInfo >();
191- const [currentTermSetInfo, setCurrentTermSetInfo] = React .useState <ITermSetInfo >();
192- const [currentLanguageTag, setCurrentLanguageTag] = React .useState <string >(" " );
193-
194- React .useEffect (() => {
195- sp .setup (props .context );
196- taxonomyService .getTermStoreInfo ()
197- .then ((termStoreInfo ) => {
198- setCurrentTermStoreInfo (termStoreInfo );
199- setCurrentLanguageTag (props .context .pageContext .cultureInfo .currentUICultureName !== ' ' ?
200- props .context .pageContext .cultureInfo .currentUICultureName :
201- currentTermStoreInfo .defaultLanguageTag );
202- });
203- taxonomyService .getTermSetInfo (Guid .parse (props .termSetId ))
204- .then ((termSetInfo ) => {
205- setCurrentTermSetInfo (termSetInfo );
206- });
207- }, []);
208-
209- return (
210- {currentTermStoreInfo && currentTermSetInfo && currentLanguageTag && (
211- <TaxonomyTree
212- languageTag = {currentLanguageTag }
213- onLoadMoreData = {taxonomyService.getTerms }
214- pageSize = {50 }
215- setTerms = {setTerms }
216- termSetInfo = {currentTermSetInfo }
217- termStoreInfo = {currentTermStoreInfo }
218- terms = {terms }
219- onRenderActionButton = {onRenderActionButton }
220- hideDeprecatedTerms = {false }
221- showIcons = {true }
222- />
223- )}
224- );
188+ import * as React from " react" ;
189+ import { Guid } from " @microsoft/sp-core-library" ;
190+ import { WebPartContext } from " @microsoft/sp-webpart-base" ;
191+ import { sp } from " @pnp/sp" ;
192+ import { ITermInfo , ITermSetInfo , ITermStoreInfo } from " @pnp/sp/taxonomy" ;
193+ import { SPTaxonomyService , TaxonomyTree } from " @pnp/spfx-controls-react" ;
194+
195+ export interface ITestTaxonomyTreeReactHooksProps {
196+ context: WebPartContext ;
197+ termSetId: string ;
198+ onRenderActionButton? : (termStoreInfo : ITermStoreInfo , termSetInfo : ITermSetInfo , termInfo : ITermInfo , updateTaxonomyTreeViewCallback ? : (newTermItems ? : ITermInfo [], updatedTermItems ? : ITermInfo [], deletedTermItems ? : ITermInfo []) => void ) => JSX .Element ;
199+ }
200+
201+ export function TestTaxonomyTreeReactHooks(
202+ props : ITestTaxonomyTreeReactHooksProps
203+ ): React .ReactElement <ITestTaxonomyTreeReactHooksProps > {
204+ const taxonomyService = new SPTaxonomyService (props .context );
205+ const [terms, setTerms] = React .useState <ITermInfo []>([]);
206+ const [currentTermStoreInfo, setCurrentTermStoreInfo] = React .useState <ITermStoreInfo >();
207+ const [currentTermSetInfo, setCurrentTermSetInfo] = React .useState <ITermSetInfo >();
208+ const [currentLanguageTag, setCurrentLanguageTag] = React .useState <string >(" " );
209+
210+ React .useEffect (() => {
211+ sp .setup (props .context );
212+ taxonomyService .getTermStoreInfo ()
213+ .then ((termStoreInfo ) => {
214+ setCurrentTermStoreInfo (termStoreInfo );
215+ setCurrentLanguageTag (props .context .pageContext .cultureInfo .currentUICultureName !== ' ' ?
216+ props .context .pageContext .cultureInfo .currentUICultureName :
217+ currentTermStoreInfo .defaultLanguageTag );
218+ });
219+ taxonomyService .getTermSetInfo (Guid .parse (props .termSetId ))
220+ .then ((termSetInfo ) => {
221+ setCurrentTermSetInfo (termSetInfo );
222+ });
223+ }, []);
224+
225+ return (
226+ currentTermStoreInfo && currentTermSetInfo && currentLanguageTag && (
227+ < TaxonomyTree
228+ languageTag = {currentLanguageTag }
229+ onLoadMoreData = {taxonomyService.getTerms }
230+ pageSize = {50 }
231+ setTerms = {setTerms }
232+ termSetInfo = {currentTermSetInfo }
233+ termStoreInfo = {currentTermStoreInfo }
234+ terms = {terms }
235+ onRenderActionButton = {props.onRenderActionButton }
236+ hideDeprecatedTerms = {false }
237+ showIcons = {true }
238+ / >
239+ ) || null
240+ );
241+ }
225242```
226243
227244![ ] ( https://telemetry.sharepointpnp.com/sp-dev-fx-controls-react/wiki/controls/ModernTaxonomyPicker )
0 commit comments