小编Mor*_*emi的帖子

在 React 中使用 Context API 和功能组件作为服务

我有一个上下文 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)

reactjs

5
推荐指数
1
解决办法
3156
查看次数

防止删除package.json的脚本部分(库角度)

我制作了一个带角度6的库。构建库时,的脚本部分package.json将被删除。我该如何防止呢?(库建立后我需要脚本部分)

如何建造: ng build --prod MyLibraryName

angular6

2
推荐指数
1
解决办法
176
查看次数

Stimulsoft - 如何在 asp.net core 中呈现报告并以角度显示

Stimulsoft 报告:

如何在 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)

如何以这种方法准备报告以正确显示角度?

stimulsoft asp.net-core angular

2
推荐指数
1
解决办法
2618
查看次数

如何在自定义钩子函数内访问 useReducer 的新状态

我有一个使用的自定义挂钩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)

reactjs react-hooks use-reducer

2
推荐指数
1
解决办法
1678
查看次数