我有一个上下文 API:
import React, { createContext, useState } from "react";
const UserContext = createContext();
const UserContextProvider = (props) => {
const [userInfo, setUserInfo] = useState({});
return (
<UserContext.Provider value={{ userInfo, setUserInfo }}>
{props.children}
</UserContext.Provider>
)
};
export { UserContextProvider, UserContext };
Run Code Online (Sandbox Code Playgroud)
并在 App.js 中使用它:
<UserContextProvider>
// Router,...
</UserContextProvider>
Run Code Online (Sandbox Code Playgroud)
好吧,我将在组件中使用上下文 API,例如服务:
import { UserContext } from "...";
function UserService() {
const { userInfo, setUserInfo } = useContext(UserContext);
const updateUserInfo = (newUserInfo) => {
setUserInfo(newUserInfo); // for example: {name:'x'}
}
return null; …Run Code Online (Sandbox Code Playgroud) 我制作了一个带角度6的库。构建库时,的脚本部分package.json将被删除。我该如何防止呢?(库建立后我需要脚本部分)
如何建造: ng build --prod MyLibraryName
如何在 asp.net core 中使用其变量和参数呈现报告并以角度显示?
角度:
viewer: any = new Stimulsoft.Viewer.StiViewer(null, 'StiViewer', false);
report: any = new Stimulsoft.Report.StiReport();
this.report.load("the report get from my api"); // ???
this.viewer.report = this.report;
this.viewer.renderHtml('viewer');
Run Code Online (Sandbox Code Playgroud)
Asp.net核心:
public async Task<IActionResult> GetReport()
{
StiReport report = new StiReport();
report.Load(@"D:\myreport.mrt"); // for example load it from local
// set parameters and variables here.it's ok
// this return does not prepare report for showing in angular.It uses for view of action
return StiNetCoreViewer.GetReportResult(this, report);
}
Run Code Online (Sandbox Code Playgroud)
如何以这种方法准备报告以正确显示角度?
我有一个使用的自定义挂钩useReducer。
function useMyCustomHook() {
const [state, dispatch] = useReducer(EntityReducer, initialState);
// console.log(state); // 1- state is up to date here
const customDispatch = (action) => {
dispatch({ ...action }); // first call EntityReducer by action.type
//2- I use state and dispatch here(for example:use state for call an api, then dispatch response)
// but the state is previous not new state?
switch (action.type) {
case "something":
// use dispatch and state here
return state;
}
}
return [state, customDispatch]; …Run Code Online (Sandbox Code Playgroud)